/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package engine.ani;

import engine.map.Map;
import engine.skill.Skill;
import engine.skill.SkillAni;
import engine.skill.SkillManager;
import function.Property;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mainpackage.Constant;
import mainpackage.GameBean;
import mainpackage.MainCanvas;
import mainpackage.MainLogic;
import mainpackage.ResManager;
import mainpackage.Tools;
import ui.UiEquipment;
import ui.UiInterFace;

/**
 *
 * @author Administrator
 */
public class Player {
    //player坐标

    public int iPlayerX = 0;
    public int iPlayerY = 0;
    public int iPlayerOldX = 0;
    public int iPlayerOldY = 0;
    //玩家的职业
    public byte iplayerOccupation = 0;
    //角色ID
    public long lPlayerID = 0L; //服务器返回的角色的ID
    public long otherPlayerId = 0L;//用于记录切磋时对方的ID
    //游戏更新状态
    public byte byPlayerUpdateState = -1;
    //玩家大状态
    public byte byPlayerBigState = -1;
    //游戏当前状态
    public byte byPlayerState = -1;
    //游戏当前方向
    public byte byPlayerDirection = -1;
    //玩家的走路速度  48像素/秒
    public short shPlayerSpeed = 60;
    //游戏更新方向
    public byte byPlayerUpdateDirection = -1;
    //任务frame间隔时间
    private long lUpdateTime;
    //当前时间
    private long lCurrentTime;
    //和服务器时间差
    private long lGapTime;
    //本地走路开始时间
    private long lStartTime;
    //走路持续时间
    private long iContinueTime;
    //1秒钟时间
    private long iSpeedTime = 1000L;
    public Skill skillPlayer = null;
    private long lWalkTime;
    //玩家走1像素所用时间
    private long shPlayerOnePelsSpeedTime;
    //记录光效和职业动作的对应关系
    private int[] skillToAction = null;
    //走路开始时间
    public long lWalkStartTime = 0;
    //走路持续时间
    public int lWalkContinueTime = 0;
//    public int[] shAvatarTypeArray = null;
    //坟墓
    public static int[] aniPlayerGrave = null;
    //玩家的名称
    public String sPlayerName = "";
    public String sTongName = null;// 帮派代号
    public byte bTongDuty = -1;//帮派职位
    public long lTongId = -1;//帮派ID
    private int nameColor;//名字颜色
    private int tongColor;//帮派颜色
    public byte bPkState;//PK状态  0 为关闭中    1 为开启中
    //玩家的等级
    public int iPlayerLevel = 0;
    //玩家的性别
    public static byte byPlayerSex = 0;
    //玩家的血量
    public int iPlayerMaxHP = 1;
    ///玩家的当前血量
    public int iPlayerHP = 0;
    //玩家的魔法值
    public int iPlayerMaxMP = 1;
    ///玩家的当前魔法值
    public int iPlayerMP = 0;
    //玩家升级需要的经验
    public long iPlayerMaxXP = 1;
    //玩家当前的经验
    public long iPlayerXP = 0;
    public int iPkPoint = 0;
    //玩家死亡
    public static boolean blPlayerDie = false;
    //路径点存储路径
    private static Vector verAutoRunPath = null;
    //存储tag目标点
    public static int[] iArrayAutoRunTagPos = null;
    //玩家寻路路径点数组
    public static int[] iAutoRunPoint = null;
    //用来标记
    private int pointSize;
    //测试用技能参照表
    public static String[] strPlayerSkill = null;
    public static int[] iPlayerSkillId = null;
    public static short[] shPlayerSkillActId = null;
    public static int[] iPlayerSkillDistance = null;
    public static int[] iPlayerSkillUseMp = null;
    //2 --- 自身
    public static byte[] byPlayerSkillType = null;
    //敌对释放  队友释放
    public static byte[] bySkillType = null;
    public static int[] iPlayerSkillCoolTime = null;
    //快捷栏冷却时间用
    public static long[] iPlayerSkillStartTime;//= new long[Constant.QUICKSET_NUMS]
    //技能冷却时间间隔
    public static long[] iPlayerSkillCoolSpaceTime;//= new long[Constant.QUICKSET_NUMS]
    //公共冷却时间 毫秒
    public static int iPublicSkillCoolTime = 1000;
    private String strCurSkillKey = null;
    public static boolean bChangeSceneLock = false;
    public boolean bPopUp = false;
    //是否可以使用物品
    public static boolean blCanUseGoods = true;
    //是否可以使用技能
    public static boolean blCanUseSkill = true;
    public static boolean blStartWalk = false;
    //资源相关
    public int iPlayerAniId = -1;
    //avatar鞋子
    private int aniAvatarShoes = -1;
    //avatar衣服
    private int aniAvatarCloes = -1;
    //avatar裤子
    private int aniAvatarTrousers = -1;
    //武器
    private int aniAvatarVeapon = -1;
    //头发
    private int aniAvatarHear = -1;
    //头
    private int aniAvatarHead = -1;
    //动画状态数组
    public int[][] iNpcAniPre;
    //是否是PK状态
    public boolean blPkState;
    //战场积分
    public short integral;
    public static boolean blNeedChangeAction = false;
    //云彩
//    private int ianiPlayerCloud =5800001;
//    private int iAniCloud[] = new int[5];
//    Image imganiPlayerCloud = null;

    public Player(byte job, byte sex, int aniid) {
        this.initPlayer(job, sex, aniid);
    }

    public void updatePosition(int x, int y, byte direction) {
        if (Math.abs(x - this.iPlayerX) > 240 || Math.abs(y - this.iPlayerY) > 320) {
            this.iPlayerX = x;
            this.iPlayerY = y;
            MainLogic.gameMap.updateMayViewXy(x - this.iPlayerX, y - this.iPlayerY, this.iPlayerX, this.iPlayerY);
            //#if NOKIA_S40V3 || NOKIAN73 || NORMAL_240_400 || MOTO || K790
//#             MainLogic.getInstance().gameMap.initOffSetXY(this.iPlayerX, this.iPlayerY);
//#             MainLogic.getInstance().gameMap.resetBuffer();
            //#else
            //#endif
        }
        this.byPlayerDirection = direction;
//        this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, false, false);
    }

    public void resetPosiontion(int x, int y) {
        MainLogic.getInstance().gameMap.initOffSetXY(x, y);
        //#if NOKIA_S40V3 || NOKIAN73 || NORMAL_240_400 || MOTO || K790
//#         MainLogic.getInstance().gameMap.resetBuffer();
        //#endif
    }

    public void resetPosition(int x, int y) {
        MainLogic.getInstance().gameMap.initOffSetXY(x, y);
        //#if NOKIA_S40V3 || NOKIAN73 || NORMAL_240_400 || MOTO || K790
//#         MainLogic.getInstance().gameMap.resetBuffer();
        //#endif
    }

    public void updateSpeed(short speed) {
//        speed = 96;
        if (Constant.DEBUG) {
            MainCanvas.addLog("速度:" + speed);
        }
        Tools.printLog("速度" + speed);
        shPlayerSpeed = speed;
        shPlayerOnePelsSpeedTime = 1000 / speed;
    }
    //初始化玩家

    public void initPlayer(byte job, byte sex, int aniid) {
        try {
//             if (Constant.DEBUG) {
//                                MainCanvas.addLog("初始化player");
//                                 MainCanvas.addLog("ROLEID:"+MainLogic.getInstance().gamePlayer.lPlayerID);
//                          }
//            ianiPlayerCloud = new Animation();
//            (iPlayerAniId, (MainLogic.byGameState == Constant.GAME_UI_CREATE_ROLE ? Constant.RES_PUBLIC_TEMP : Constant.RES_PUBLIC_FINAL), false);
//            ResManager.loadAnimation(ianiPlayerCloud, Constant.RES_PUBLIC_FINAL, false);
//            imganiPlayerCloud = Image.createImage(Constant.RES_UI_PATH + "5800002.png");
//            System.out.println(Constant.RES_UI_PATH + "5800002.png");
//             System.out.println(Constant.RES_UI_PATH + imganiPlayerCloud.getHeight());
//            for(int i= 0; i < 5; i++)
//                iAniCloud[i] = 0;
            iVatarIndex = 0;
            this.iPlayerX = 0;
            this.iPlayerY = 0;
            this.skillPlayer = new Skill();
            this.skillToAction = new int[Constant.PLAYER_SKILL_AND_ACTION];
            this.iNpcAniPre = new int[Constant.PLAYER_AVATAR_MAX_NUMS][5];
//            this.byPlayerState = 1;
            //添加技能动作和光效播放参照表---测试用
            this.iplayerOccupation = job;
            if (aniid == -1) {
                iPlayerAniId = (sex == Constant.PLAYER_SEX_WOMAN) ? Constant.RES_PLAYER_WOMEN_ANI_PATH : Constant.RES_PLAYER_MAN_ANI_PATH;
            } else {
                iPlayerAniId = aniid;
            }
//            public final static byte PLAYER_OCCUPTION_ASSASSIN = 1;//刺客
//    public final static byte PLAYER_OCCUPTION_SWORD = 2; //武师
//    public final static byte PLAYER_OCCUPTION_MASTER = 4;//术士
            //#if NOKIA_S40V3 || MOTO || K790
//#             switch(sex)
//#             {
//#                 case Constant.PLAYER_SEX_WOMAN:
//#                     switch(job)
//#                     {
//#                         case Constant.PLAYER_OCCUPTION_ASSASSIN:
//#                              iPlayerAniId = 6000004;
//#                             break;
//#                             case Constant.PLAYER_OCCUPTION_SWORD:
//#                              iPlayerAniId = 6000002;
//#                             break;
//#                              case Constant.PLAYER_OCCUPTION_MASTER:
//#                               iPlayerAniId = 6000006;
//#                             break;
//#                     }
//#                 break;
//#                  case  Constant.PLAYER_SEX_MAN:
//#                       switch(job)
//#                     {
//#                         case Constant.PLAYER_OCCUPTION_ASSASSIN:
//#                             iPlayerAniId = 6000003;
//#                             break;
//#                             case Constant.PLAYER_OCCUPTION_SWORD:
//#                                 iPlayerAniId = 6000001;
//#                             break;
//#                              case Constant.PLAYER_OCCUPTION_MASTER:
//#                                     iPlayerAniId = 6000005;
//#                             break;
//#                     }
//#                 break;
//#             }
            //#endif
//            this.addSkillToAction(0, Constant.PLAYER_ACTION_ID_RIGHT_SKILL_FIGHT, 3, -5, 3);
//            this.addSkillToAction(1, Constant.PLAYER_ACTION_ID_RIGHT_SRRONG_SKILL_FIGHT, 3, -5, 3);
            //如果是女角色
            Tools.printLog("载入玩家：job" + job + "sex" + sex);
            byPlayerSex = sex;
//            if (iPlayerAniId != Constant.RES_PLAYER_MAN_SWORD_ANI_PATH) 
            {
                //#if NOKIA_S40V3 || NORMAL_240_400 || MOTO || K790
//#                 ResManager.loadAnimation(iPlayerAniId, (MainLogic.byGameState == Constant.GAME_UI_CREATE_ROLE ? Constant.RES_PUBLIC_TEMP : Constant.RES_PUBLIC_FINAL), false);
                //#else
                ResManager.loadAnimation(iPlayerAniId, (MainLogic.byGameState == Constant.GAME_UI_CREATE_ROLE ? Constant.RES_PUBLIC_TEMP : Constant.RES_PUBLIC_FINAL), false);
                //#endif
            }
            this.changeAction(Constant.PLAYER_STATE_STAND, Constant.PLAYER_DIRECTION_DOWN, true, true);
            ResManager.loadAnimation(Constant.RES_PLAYER_GRAVE_ANI_PATH, Constant.RES_PUBLIC_FINAL, false);
            for (int j = 0; j < Constant.PLAYER_AVATAR_MAX_NUMS; j++) {
                for (int i = 0; i < 5; i++) {
                    this.iNpcAniPre[j][i] = 0;
                }
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    public void addPlayerSkill(int nums, int index, String skillkey, byte skillType, int skillId, String actId, int coolTime, int SkillDistance, int SkillUseMp, byte SkillType) {
        if (strPlayerSkill == null) {
            strPlayerSkill = new String[nums];
            iPlayerSkillId = new int[nums];
            shPlayerSkillActId = new short[nums];
            byPlayerSkillType = new byte[nums];
            iPlayerSkillCoolTime = new int[nums];
            iPlayerSkillStartTime = new long[nums];
            iPlayerSkillCoolSpaceTime = new long[nums];
            bySkillType = new byte[nums];
            iPlayerSkillDistance = new int[nums];
            iPlayerSkillUseMp = new int[nums];
        }
        strPlayerSkill[index] = skillkey;
        iPlayerSkillId[index] = skillId;
        int indexa = actId.indexOf(",");
        if (indexa != -1) {
            //#if NOKIA_S40V3 || NORMAL_240_400 || MOTO || K790
//#             actId = actId.substring(indexa + 1);//substring(index + 1)
            //#else
            actId = actId.substring(0, indexa);
            //#endif
        }
        shPlayerSkillActId[index] = Short.parseShort(actId);
        byPlayerSkillType[index] = skillType;
        iPlayerSkillCoolTime[index] = coolTime + 500;
        iPlayerSkillStartTime[index] = -1;
        iPlayerSkillCoolSpaceTime[index] = -1;
        iPlayerSkillDistance[index] = SkillDistance;
        if (SkillUseMp == 0) {
            iPlayerSkillUseMp[index] = SkillUseMp;
        } else {
            iPlayerSkillUseMp[index] = -SkillUseMp;
        }
        bySkillType[index] = SkillType;
        Tools.printLog("strPlayerSkill[index]" + strPlayerSkill[index] + " iPlayerSkillCoolTime[index]" + iPlayerSkillCoolTime[index]);
    }
    //更新玩家技能

    public static void setPlayerSkillCDTime(int index) {
        if (strPlayerSkill == null) {
            return;
        }
        long continuetime = 0;
        //第一
        for (int i = 0; i < iPlayerSkillStartTime.length; i++) {
            if (iPlayerSkillStartTime[i] == -1) {
                iPlayerSkillStartTime[i] = System.currentTimeMillis();
                if (i == index) {
                    iPlayerSkillCoolSpaceTime[i] = iPlayerSkillCoolTime[i];
                    Tools.printLog("设置冷却时间" + i + iPlayerSkillCoolSpaceTime[i]);
                } else {
                    iPlayerSkillCoolSpaceTime[i] = iPublicSkillCoolTime;
                    Tools.printLog("设置冷却时间iPublicSkillCoolTime" + i + iPlayerSkillCoolSpaceTime[i]);
                }
            }
        }
    }
//String skillkey, byte skillType, int skillId, short actId, int coolTime, int SkillDistance, int SkillUseMp, byte SkillType) {

    public void addOnePlayerSkill(int nums, String skillkey, byte skillType, int skillId, String actId,
            int iPlayerCoolTime, int skillDistance, int skillMp, byte skillAttackType) {
        boolean haveSkillnums = true;
        if (strPlayerSkill == null) {
            strPlayerSkill = new String[nums];
            iPlayerSkillId = new int[nums];
            shPlayerSkillActId = new short[nums];
            byPlayerSkillType = new byte[nums];
            iPlayerSkillCoolTime = new int[nums];
            iPlayerSkillDistance = new int[nums];
            iPlayerSkillStartTime = new long[nums];
            iPlayerSkillCoolSpaceTime = new long[nums];
            iPlayerSkillUseMp = new int[nums];
            bySkillType = new byte[nums];
            haveSkillnums = false;
        }
//        else
        {
            int length = strPlayerSkill.length - (haveSkillnums ? 0 : 1);
            String[] tempkey = new String[length + 1];
            int[] tempid = new int[length + 1];
            short[] tempAct = new short[length + 1];
            byte[] tempskillType = new byte[length + 1];
            int[] tempCool = new int[length + 1];
            int[] tempDis = new int[length + 1];
            int[] tempMp = new int[length + 1];
            byte[] tempType = new byte[length + 1];
            long[] tempStartT = new long[length + 1];
            long[] tempSpaceT = new long[length + 1];
            System.arraycopy(strPlayerSkill, 0, tempkey, 0, strPlayerSkill.length);
            System.arraycopy(iPlayerSkillId, 0, tempid, 0, iPlayerSkillId.length);
            System.arraycopy(shPlayerSkillActId, 0, tempAct, 0, shPlayerSkillActId.length);
            System.arraycopy(byPlayerSkillType, 0, tempskillType, 0, byPlayerSkillType.length);
            //
            System.arraycopy(iPlayerSkillCoolTime, 0, tempCool, 0, iPlayerSkillCoolTime.length);
            System.arraycopy(iPlayerSkillDistance, 0, tempDis, 0, iPlayerSkillDistance.length);
            System.arraycopy(iPlayerSkillUseMp, 0, tempMp, 0, iPlayerSkillUseMp.length);
            System.arraycopy(bySkillType, 0, tempType, 0, bySkillType.length);
            System.arraycopy(iPlayerSkillStartTime, 0, tempStartT, 0, iPlayerSkillStartTime.length);
            System.arraycopy(iPlayerSkillCoolSpaceTime, 0, tempSpaceT, 0, iPlayerSkillCoolSpaceTime.length);
            tempkey[length] = skillkey;
            tempid[length] = skillId;
            tempskillType[length] = skillType;
            int indexa = actId.indexOf(",");
            if (indexa != -1) {
                //#if NOKIA_S40V3 || NORMAL_240_400 || MOTO || K790
//#                 actId = actId.substring(indexa + 1);//substring(index + 1)
                //#else
                actId = actId.substring(0, indexa);
                //#endif
            }
            tempAct[length] = Short.parseShort(actId);
            tempCool[length] = iPlayerCoolTime + 500;
            tempDis[length] = skillDistance;
            tempMp[length] = skillMp;
            tempType[length] = skillAttackType;
            tempStartT[length] = -1;
            tempSpaceT[length] = -1;
            ////////////
            //  iPlayerSkillCoolTime[index] = coolTime;
//        iPlayerSkillDistance[index] = SkillDistance;
//        if (SkillUseMp == 0) {
//            iPlayerSkillUseMp[index] = SkillUseMp;
//        } else {
//            iPlayerSkillUseMp[index] = -SkillUseMp;
//        }
//        bySkillType[index] = SkillType;
            ///////////////////
//            for (int i = 0; i < strPlayerSkill.length; i++) {
//                Tools.printLog("strPlayerSkill" + i + strPlayerSkill[i]);
//                Tools.printLog("iPlayerSkillId" + i + iPlayerSkillId[i]);
//                Tools.printLog("shPlayerSkillActId" + i + shPlayerSkillActId[i]);
//            }
            Tools.printLog("learn skill");
            strPlayerSkill = (String[]) tempkey;
            iPlayerSkillId = (int[]) tempid;
            shPlayerSkillActId = (short[]) tempAct;
            byPlayerSkillType = (byte[]) tempskillType;
            iPlayerSkillCoolTime = (int[]) tempCool;
            iPlayerSkillDistance = (int[]) tempDis;
            iPlayerSkillUseMp = (int[]) tempMp;
            bySkillType = (byte[]) tempType;
            iPlayerSkillStartTime = (long[]) tempStartT;
            iPlayerSkillCoolSpaceTime = (long[]) tempSpaceT;
//            for (int i = 0; i < strPlayerSkill.length; i++) {
//                Tools.printLog("strPlayerSkill" + i + strPlayerSkill[i]);
//                Tools.printLog("iPlayerSkillId" + i + iPlayerSkillId[i]);
//                Tools.printLog("shPlayerSkillActId" + i + shPlayerSkillActId[i]);
//            }
            tempkey = null;
            tempid = null;
            tempAct = null;
            tempCool = null;
            tempDis = null;
            tempMp = null;
            tempType = null;
            tempStartT = null;
            tempSpaceT = null;
            tempskillType = null;
        }
        Tools.printLog("玩家技能-----：" + skillkey + "id:" + skillId);
    }

    public void setSkillKey(String skillkey) {
        strCurSkillKey = skillkey;
    }

    public String getSkillKey() {
        return strCurSkillKey;
    }

    public int getSkillIndex(String skillkey) {
        for (int i = 0; i < strPlayerSkill.length; i++) {
            if (strPlayerSkill[i].equals(skillkey)) {
                return i;
            }
        }
        return 0;
    }
    /*
     * 如果本地有取本地，如果本地没有走服务器
     */
    public static int iVatarIndex = 0;

    public void changeAvatar(String vatarId) {
        try {
            int index = vatarId.indexOf(",");
            int avatarId = -1;
            if (index != -1) {
                avatarId = (byPlayerSex == Constant.PLAYER_SEX_MAN) ? Integer.parseInt(vatarId.substring(0, index)) : Integer.parseInt(vatarId.substring(index + 1));
            } else {
                avatarId = Integer.parseInt(vatarId);
            }
            if (avatarId == Constant.RES_PLAYER_WOMEN_ANI_PATH || avatarId == Constant.RES_PLAYER_MAN_ANI_PATH) {
                //#if NOKIA_S40V3 || MOTO || K790
//#             switch(byPlayerSex)
//#             {
//#                 case Constant.PLAYER_SEX_WOMAN:
//#                     switch(iplayerOccupation)
//#                     {
//#                         case Constant.PLAYER_OCCUPTION_ASSASSIN:
//#                              avatarId = 6000004;
//#                             break;
//#                             case Constant.PLAYER_OCCUPTION_SWORD:
//#                              avatarId = 6000002;
//#                             break;
//#                              case Constant.PLAYER_OCCUPTION_MASTER:
//#                               avatarId = 6000006;
//#                             break;
//#                     }
//#                 break;
//#                  case  Constant.PLAYER_SEX_MAN:
//#                       switch(iplayerOccupation)
//#                     {
//#                         case Constant.PLAYER_OCCUPTION_ASSASSIN:
//#                             avatarId = 6000003;
//#                             break;
//#                             case Constant.PLAYER_OCCUPTION_SWORD:
//#                                 avatarId = 6000001;
//#                             break;
//#                              case Constant.PLAYER_OCCUPTION_MASTER:
//#                                     avatarId = 6000005;
//#                             break;
//#                     }
//#                 break;
//#             }
                //#endif
            }
            if (iPlayerAniId != avatarId) {
                iPlayerAniId = avatarId;
                ResManager.loadAnimation(iPlayerAniId, Constant.RES_PUBLIC_FINAL, true);
                for (int j = 0; j < Constant.PLAYER_AVATAR_MAX_NUMS; j++) {
                    for (int i = 0; i < 5; i++) {
                        this.iNpcAniPre[j][i] = 0;
                    }
                }
                this.changeAction(Constant.PLAYER_STATE_STAND, Constant.PLAYER_DIRECTION_DOWN, true, true);
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    public void addAvatorAni(String vatarId, byte position, boolean blmustbe) {
        //#if NOKIA_S40V3 || NORMAL_240_400 || MOTO || K790
//#         return;
//#else
        if (blmustbe) {
            try {
                int index = vatarId.indexOf(",");
                int avatarId = -1;
                if (index != -1) {
                    avatarId = (byPlayerSex == Constant.PLAYER_SEX_MAN) ? Integer.parseInt(vatarId.substring(0, index)) : Integer.parseInt(vatarId.substring(index + 1));
                } else {
                    avatarId = Integer.parseInt(vatarId);
                }
                Tools.printLog("add avatar id:" + avatarId);
                switch (position) {
                    case Constant.PLAYER_AVATAR_SHOES:
                        this.aniAvatarShoes = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_CLOTH:
                        this.aniAvatarCloes = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_TROUSERS:
                        this.aniAvatarTrousers = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_WEAPON:
                        this.aniAvatarVeapon = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_HEAR:
                        this.aniAvatarHear = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_HEAD:
                        this.aniAvatarHead = avatarId;
                        break;
                    default:
                        break;
                }
                ResManager.loadAnimation(avatarId, Constant.NET_TYPE_PLAYER_AVATAR_ANI, true);
                this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, true, false);

            } catch (Exception e) {
                if (Constant.DEBUG) {
                    e.printStackTrace();
                }
            }
        } else {
//#if NOKIA_S40V3 || NORMAL_240_400 || MOTO || K790
//#         return;
//#else
            try {
                int index = vatarId.indexOf(",");
                int avatarId = -1;
                if (index != -1) {
                    avatarId = (byPlayerSex == Constant.PLAYER_SEX_MAN) ? Integer.parseInt(vatarId.substring(0, index)) : Integer.parseInt(vatarId.substring(index + 1));
                } else {
                    avatarId = Integer.parseInt(vatarId);
                }
                switch (position) {
                    case Constant.PLAYER_AVATAR_SHOES:
                        this.aniAvatarShoes = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_CLOTH:
                        this.aniAvatarCloes = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_TROUSERS:
                        this.aniAvatarTrousers = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_WEAPON:
                        this.aniAvatarVeapon = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_HEAR:
                        this.aniAvatarHear = avatarId;
                        break;
                    case Constant.PLAYER_AVATAR_HEAD:
                        this.aniAvatarHead = avatarId;
                        break;
                }
                ResManager.loadAnimation(avatarId, Constant.NET_TYPE_PLAYER_AVATAR_ANI, true);
                this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, true, false);
            } catch (Exception e) {
                if (Constant.DEBUG) {
                    e.printStackTrace();
                }
            }
            //#endif
        }
        //#endif
    }
    //增加技能和动作的对应关系

    public void deleteAvatorAni(byte position) {
        try {
            Tools.printLog("delete position id:" + position);
            switch (position) {
                case Constant.PLAYER_AVATAR_SHOES:
                    this.aniAvatarShoes = -1;
                    break;
                case Constant.PLAYER_AVATAR_CLOTH:
                    this.aniAvatarCloes = -1;
                    break;
                case Constant.PLAYER_AVATAR_TROUSERS:
                    this.aniAvatarTrousers = -1;
                    break;
                case Constant.PLAYER_AVATAR_WEAPON:
                    this.aniAvatarVeapon = -1;
                    break;
                case Constant.PLAYER_AVATAR_HEAR:
                    this.aniAvatarHear = -1;
                    break;
                case Constant.PLAYER_AVATAR_HEAD:
                    this.aniAvatarHead = -1;
                    break;
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    public void addSkillToAction(int index, int actId, int iFrameIndex, int posX, int posY) {
        this.skillToAction[index * 5] = actId;
        this.skillToAction[index * 5 + 1] = iFrameIndex;
        this.skillToAction[index * 5 + 2] = posX;
        this.skillToAction[index * 5 + 3] = posY;
    }

    public void showOnlyAni(Graphics g, int x, int y, int state, byte byDirection) {
        if (blNeedChangeAction) {
            this.changeAction(this.byPlayerState, this.byPlayerDirection, false, true);
            blNeedChangeAction = false;
        }
        if (state != Constant.PLAYER_STATE_STAND || this.byPlayerDirection != byDirection) {
            this.changeAction(Constant.PLAYER_STATE_STAND, byDirection, true, false);
        }
        if (showAvatarAction(((this.byPlayerState == Constant.PLAYER_STATE_FIGHT) ? false : true), g, x, y)) {
            this.changeAction(this.byPlayerState, this.byPlayerDirection, false, true);
        }
    }

    public void show(Graphics g, int x, int y) {
        if (this.byPlayerState == Constant.PLAYER_STATE_DIE) {
            showPlayerDie(g, iPlayerX - x, iPlayerY - y);
        } else {
            if (Player.iPetsAniId != -1 && this.iPetY < iPlayerY) {
                if (UiEquipment.isopenset[15]) {
                    ResManager.drawAnimation(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), this.iNpcAniPre[5], g, iPetX - x, iPetY - y, true);
                    g.setColor(0xffcc00);
                    g.drawString(this.sPetNick, iPetX - x - (Constant.FONT_SMALL.stringWidth(this.sPetNick) >> 1), iPetY - y - shPetHeight - Constant.FONT_SMALL_HEIGHT, 0);
                }
            }
//            if(MainLogic.blLogined)
//                g.drawImage(imganiPlayerCloud, iPlayerX - x- imganiPlayerCloud.getWidth()/2+5, iPlayerY - y-25, 20);
//             ResManager.drawAnimation(ResManager.getAnimation(ianiPlayerCloud, Constant.RES_PUBLIC_FINAL), this.iAniCloud, g, iPlayerX - x, iPlayerY - y, true);
//              y += 20;
             show(g, iPlayerX - x, iPlayerY - y, false, false);
            if (GameBean.BL_PLAYER_ENTER_CENCE) {
                //#if NOKIA_S40V3 || NOKIA_S60V5 || NORMAL_240_400 || MOTO || K790
                 nameColor = 0xffcc00;
                //#else
//#                nameColor = 0xffffff;
                //#endif
                if (iPkPoint > 0 && iPkPoint < 30) {
                    nameColor = 0xffcc00;
                } else if (iPkPoint >= 30) {
                    nameColor = 0xff3333;
                }
                if (sTongName == null) {
                    Tools.drawShadowString(g, (byte) 0, this.sPlayerName, iPlayerX - x - (Constant.FONT_SMALL.stringWidth(this.sPlayerName) >> 1), iPlayerY - y - 80, nameColor, 0x333333);
                } else {
                    switch (bTongDuty) {
                        case 0://帮众
                            //#if NOKIA_S40V3 || NOKIA_S60V5 || NORMAL_240_400 || MOTO || K790
                             tongColor = 0x00ffff;
                            //#else
//#                            tongColor = 0xffffff;
                            //#endif
                            break;
                        case 1://长老
                            tongColor = 0x00ffff;
                            break;
                        case 2://护法
                            tongColor = 0x0099ff;
                            break;
                        case 3://副帮主
                            tongColor = 0xffff00;
                            break;
                        case 4://帮主
                            tongColor = 0xffcc00;
                            break;
                    }
                    Tools.drawShadowString(g, (byte) 1, this.sTongName, iPlayerX - x
                            - (Constant.FONT_SMALL.stringWidth(this.sPlayerName + this.sTongName) >> 1),
                            iPlayerY - y - 80, tongColor, 0x333333);
                    Tools.drawShadowString(g, (byte) 1, this.sPlayerName, iPlayerX - x
                            - (Constant.FONT_SMALL.stringWidth(this.sPlayerName + this.sTongName) >> 1)
                            + Constant.FONT_SMALL.stringWidth(this.sTongName), iPlayerY - y - 80, nameColor, 0x333333);
                }
            }
            //宠物覆盖人物f
            if (this.iPetsAniId != -1 && this.iPetY >= this.iPlayerY) {
                if (MainLogic.getInstance().uiEquipment.isopenset[15]) {
                    ResManager.drawAnimation(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), this.iNpcAniPre[5], g, iPetX - x, iPetY - y, true);
                    g.setColor(0xffcc00);
                    g.drawString(this.sPetNick, iPetX - x - (Constant.FONT_SMALL.stringWidth(this.sPetNick) >> 1), iPetY - y - shPetHeight - Constant.FONT_SMALL_HEIGHT, 0);
                }
            }
        }
        //绘制宠物说话
        if (MainLogic.getInstance().uiEquipment.isopenset[12]) {
            this.drawPetTalk(g, x, y);
        }
    }

    public void show(Graphics g, int x, int y, boolean mirror, boolean apeak) {
        //绘制npc动画
        if (this.byPlayerState == Constant.PLAYER_STATE_DIE) {
            showPlayerDie(g, x, y);
        } else {
            if (showAvatarAction(((this.byPlayerState == Constant.PLAYER_STATE_FIGHT) ? false : true), g, x, y)) {
                this.changeAction(this.byPlayerState, this.byPlayerDirection, false, true);
            }
        }
    }

    public void updateRole() {
        try {
            if (bChangeSceneLock) {
                Tools.printLog("bChangeSceneLock卡住了");
                return;
            }
            //非冰冻状态更新玩家
            //更新玩家死亡状态
            //状态判断逻辑
            if (this.byPlayerState == Constant.PLAYER_STATE_DIE) {
                if (MainLogic.getInstance().byGameState != Constant.GAME_UI_REVIVE) {
                    MainLogic.getInstance().pushState(Constant.GAME_UI_REVIVE, true);
                    MainLogic.getInstance().uiInterFace.initRevive(iPlayerLevel);
                    //清除锁定
                    MainLogic.getInstance().clearLockedObj(0, true);
                }
                if (aniPlayerGrave == null) {
                    aniPlayerGrave = new int[5];
                    ResManager.changeAction(ResManager.getAnimation(Constant.RES_PLAYER_GRAVE_ANI_PATH, Constant.RES_PUBLIC_FINAL), 1, 0, aniPlayerGrave);
                }
                //人死了宠物收回
                if (this.iPetsAniId > 0) {
                    this.deletePetsAni();
                }
                return;
            }
            this.changeState();
            this.checkSkillStart();
            //状态切换时间计算
            this.lCurrentTime = System.currentTimeMillis();
            //玩家各个状态更新逻辑
            switch (this.byPlayerState) {
                case Constant.PLAYER_STATE_RUN:
                    this.playerRun();
                    break;
                case Constant.PLAYER_STATE_AUTO_RUN:
                    this.playerAutoRun();
                    break;
            }
            //更新宠物逻辑
            this.updatePetShow();
            //更新玩家异常状态
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    //检测技能开始状态
    public void checkSkillStart() {
        if (this.byPlayerState == Constant.PLAYER_STATE_FIGHT) {
//            if (MainLogic.getInstance().aSkillManager.skillTable.isEmpty())
//                {
//                return;
//                }
//            int actIndex = MainLogic.getInstance().gamePlayer.skillPlayer.getSkillActionId();
//            if (actIndex == -1)
//                {
//                return;
//                }
            SkillAni aSkillAni = null;
            if (this.skillPlayer.getSkillActionKey() != null) {
                if (MainLogic.getInstance().iLockedObjNumber[0][0] != -1 || this.skillPlayer.getSkillActionType() == Constant.SKILL_TYPE_PLAYERSELF|| this.skillPlayer.getSkillActionType() == Constant.SKILL_TYPE_AREA) {
                    if (this.skillPlayer.getSkillActionId() == -1) {
                        return;
                    }
                    Tools.printLog("技能索引" + MainLogic.getInstance().aSkillManager.getSkillIndex(this.skillPlayer.getSkillActionId()) + "技能索引2" + this.skillPlayer.getSkillActionId());
                    if (this.skillPlayer.getSkillKeyIndex() == -1) {
                        this.skillPlayer.setSkillKeyIndex(MainLogic.getInstance().aSkillManager.getSkillIndex(this.skillPlayer.getSkillActionId()));
                    }
                    Tools.printLog("等待frame" + SkillManager.bySkillActPreFirstActTim[this.skillPlayer.getSkillKeyIndex()]);
                    Tools.printLog("当前技能key索引" + this.skillPlayer.getSkillKeyIndex());
                    Tools.printLog("当前技能type" + this.skillPlayer.getSkillActionType());
                    if (this.skillPlayer.getSkillKeyIndex() != -1) {
                        if (MainLogic.getInstance().uiEquipment.isopenset[11]) {
                            MainLogic.getInstance().aSkillManager.addSkillAni(SkillManager.getSkillIndex(this.skillPlayer.getSkillActionId()), SkillManager.isPlayerJobSkillType(this.skillPlayer.getSkillActionId()) ? Constant.SKILL_TYPE_PLAYER_HEART : Constant.SKILL_TYPE_PLAYER, Player.byPlayerSex, this.skillPlayer.getSkillActionKey(), this.skillPlayer.getSkillActionId(), MainLogic.getInstance().gamePlayer.iPlayerX, MainLogic.getInstance().gamePlayer.iPlayerY,
                                    (int) ((this.skillPlayer.getSkillActionType() == Constant.SKILL_TYPE_PLAYERSELF|| this.skillPlayer.getSkillActionType() == Constant.SKILL_TYPE_AREA) ? MainLogic.getInstance().gamePlayer.iPlayerX : MainLogic.getInstance().iLockedObjNumber[0][2]), ((this.skillPlayer.getSkillActionType() == Constant.SKILL_TYPE_PLAYERSELF|| this.skillPlayer.getSkillActionType() == Constant.SKILL_TYPE_AREA) ? MainLogic.getInstance().gamePlayer.iPlayerY : (int) MainLogic.getInstance().iLockedObjNumber[0][3]), MainLogic.getInstance().gamePlayer.byPlayerDirection);
                        }
                        this.skillPlayer.setSkillActionKey(null);
                    }
                } else {
                    this.skillPlayer.setSkillActionKey(null);
                }
            }
        }
    }
    //角色跑动
    int index = 1;
    //玩家1秒走的距离
    private int iMoveDistance = 0;

    public void playerRun() {
        if (!blPlayerRun) {
            if (Constant.DEBUG) {
                MainCanvas.addLog("blPlayerRun:" + blPlayerRun);
            }
            return;
        }
        if (shPlayerSpeed == 0) {
            if (Constant.DEBUG) {
                MainCanvas.addLog("shPlayerSpeed:" + shPlayerSpeed);
            }
            this.iMoveDistance = 0;
            return;
        }
        //首先和服务器同步时间，得到时间差，如果在1秒内计算1秒的剩余时间--再计算步长 否则超过1秒后累计到下次步长计算。如果中途停止走路告知服务器即可
        int iStep = 0;
        //1秒内持续时间 = （当前时间 - 走路开始时间）

        //到1秒了如果走到距离不到48像素强行职位到48像素变向的误差不计
        if ((this.lCurrentTime - this.lStartTime) > 1000L) {
            this.lStartTime = this.lCurrentTime;
            iStep = this.iMoveDistance - shPlayerSpeed;
            this.iMoveDistance = 0;
        } else {
//走路间隔时间
            if (this.iMoveDistance > shPlayerSpeed) {
                iStep = 0;
            } else if (this.iMoveDistance == 0) {
                iStep = shPlayerSpeed / 12;
                this.iMoveDistance = shPlayerSpeed / 12;
            } else {
                this.shPlayerOnePelsSpeedTime = (1000 - (this.lUpdateTime - this.lStartTime)) / (shPlayerSpeed - this.iMoveDistance);
                iStep = (int) ((this.lCurrentTime - this.lUpdateTime) / this.shPlayerOnePelsSpeedTime);
                this.lUpdateTime = System.currentTimeMillis();
                this.iMoveDistance += iStep;
            }
        }
        //是否切换场景
        boolean blChangeScene = false;
        if (iStep <= 0) {
            if (Constant.DEBUG) {
                MainCanvas.addLog("iStep:" + iStep + "Speed" + shPlayerSpeed);
            }
            return;
        }
        //#if NOKIA_S40V3 || NOKIAN73 || NORMAL_240_400 || MOTO || K790
//#         if (iStep >= 16 || iStep <= -16) {
//#             iStep = 8;
//#         }
        //#else
        //#endif
        if (Constant.DEBUG) {
            MainCanvas.addLog("iStep:" + iStep + "Speed" + shPlayerSpeed);
        }
        Tools.printLog("iStep" + iStep);
        switch (this.byPlayerDirection) {
            case Constant.PLAYER_DIRECTION_UP:
                iStep = -iStep;
                this.iPlayerY += iStep;
                blChangeScene = MainLogic.gameMap.updateMayViewXy(0, iStep, this.iPlayerX, this.iPlayerY);
                break;
            case Constant.PLAYER_DIRECTION_DOWN:
                this.iPlayerY += iStep;
                blChangeScene = MainLogic.gameMap.updateMayViewXy(0, iStep, this.iPlayerX, this.iPlayerY);
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                iStep = -iStep;
                this.iPlayerX += iStep;
                blChangeScene = MainLogic.gameMap.updateMayViewXy(iStep, 0, this.iPlayerX, this.iPlayerY);
                break;
            case Constant.PLAYER_DIRECTION_RIGHT:
                this.iPlayerX += iStep;
                blChangeScene = MainLogic.gameMap.updateMayViewXy(iStep, 0, this.iPlayerX, this.iPlayerY);
                break;
        }
        //如果不能走
        byte byCango = MainLogic.gameMap.canNotGo(this.iPlayerX, this.iPlayerY, this.byPlayerDirection);
        Tools.printLog("byCango" + byCango);
        if (!blChangeScene && byCango == 1) {
            iStep = Math.abs(iStep);
            switch (this.byPlayerDirection) {
                case Constant.PLAYER_DIRECTION_UP:
                    this.iPlayerY += iStep;
                    blChangeScene = MainLogic.gameMap.updateMayViewXy(0, iStep, this.iPlayerX, this.iPlayerY);
                    break;
                case Constant.PLAYER_DIRECTION_DOWN:
                    iStep = -iStep;
                    this.iPlayerY += iStep;
                    blChangeScene = MainLogic.gameMap.updateMayViewXy(0, iStep, this.iPlayerX, this.iPlayerY);
                    break;
                case Constant.PLAYER_DIRECTION_LEFT:
                    this.iPlayerX += iStep;
                    blChangeScene = MainLogic.gameMap.updateMayViewXy(iStep, 0, this.iPlayerX, this.iPlayerY);
                    break;
                case Constant.PLAYER_DIRECTION_RIGHT:
                    iStep = -iStep;
                    this.iPlayerX += iStep;
                    blChangeScene = MainLogic.gameMap.updateMayViewXy(iStep, 0, this.iPlayerX, this.iPlayerY);
                    break;
            }
            this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, true, false);
            return;
        } else if (!bChangeSceneLock && byCango == 2 && !bPopUp) {
            //如果新手区没接受指定任务
//            if (!GameBean.BL_NEWPLAYER_CAN_GO_LOCK || !MainLogic.getInstance().uiInterFace.sRoamMapName.equals("女娲圣域"))
            {
                bChangeSceneLock = true;
                this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, false, false);
                lcontinueTime = System.currentTimeMillis();
                MainLogic.getInstance().send(Constant.MSG_NET_WALK, Constant.SOCKET_MSG_TYPE_LOGIC);
            }
        }
        if ((System.currentTimeMillis() - lcontinueTime) >= 1000) {
            lcontinueTime = System.currentTimeMillis();
            MainLogic.getInstance().send(Constant.MSG_NET_WALK, Constant.SOCKET_MSG_TYPE_LOGIC);
        }
    }
    public long lcontinueTime = 0L;
    //是否到达路径点
    private static boolean blHasArrivePoint = false;

    public void playerAutoRun() {
        if (shPlayerSpeed == 0) {
            this.iMoveDistance = 0;
            return;
        }
        //首先和服务器同步时间，得到时间差，如果在1秒内计算1秒的剩余时间--再计算步长 否则超过1秒后累计到下次步长计算。如果中途停止走路告知服务器即可
        int iStep = 0;
        //1秒内持续时间 = （当前时间 - 走路开始时间）

        //到1秒了如果走到距离不到48像素强行职位到48像素变向的误差不计
        if ((this.lCurrentTime - this.lStartTime) > 1000L) {
            this.lStartTime = this.lCurrentTime;
            iStep = this.iMoveDistance - shPlayerSpeed;
            this.iMoveDistance = 0;
        } else {
//走路间隔时间
            if (this.iMoveDistance > shPlayerSpeed) {
                iStep = 0;
            } else if (this.iMoveDistance == 0) {
                iStep = shPlayerSpeed / 12;
                this.iMoveDistance = shPlayerSpeed / 12;
            } else {
                this.shPlayerOnePelsSpeedTime = (1000 - (this.lUpdateTime - this.lStartTime)) / (shPlayerSpeed - this.iMoveDistance);
                iStep = (int) ((this.lCurrentTime - this.lUpdateTime) / this.shPlayerOnePelsSpeedTime);
                this.lUpdateTime = System.currentTimeMillis();
                this.iMoveDistance += iStep;
            }
        }
        //是否切换场景
        boolean blChangeScene = false;
        if (iStep <= 0) {
            return;
        }
        //#if NOKIA_S40V3 || NOKIAN73 || NORMAL_240_400 || MOTO || K790
//#         if (iStep >= 16 || iStep <= -16) {
//#             iStep = 8;
//#         }
        //#else
        //#endif
        switch (this.byPlayerDirection) {
            case Constant.PLAYER_DIRECTION_UP:
                iStep = -iStep;
                this.iPlayerY += iStep;
                blChangeScene = MainLogic.gameMap.updateMayViewXy(0, iStep, this.iPlayerX, this.iPlayerY);
                break;
            case Constant.PLAYER_DIRECTION_DOWN:
                this.iPlayerY += iStep;
                blChangeScene = MainLogic.gameMap.updateMayViewXy(0, iStep, this.iPlayerX, this.iPlayerY);
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                iStep = -iStep;
                this.iPlayerX += iStep;
                blChangeScene = MainLogic.gameMap.updateMayViewXy(iStep, 0, this.iPlayerX, this.iPlayerY);
                break;
            case Constant.PLAYER_DIRECTION_RIGHT:
                this.iPlayerX += iStep;
                blChangeScene = MainLogic.gameMap.updateMayViewXy(iStep, 0, this.iPlayerX, this.iPlayerY);
                break;
        }
        byte byCango = MainLogic.gameMap.canNotGo(this.iPlayerX, this.iPlayerY, this.byPlayerDirection);
        if (this.arrivePoint(this.iPlayerX, this.iPlayerY)) {
//            MainLogic.gameMap.updateMayViewXy(iStep, iStep, this.iPlayerX, this.iPlayerY);
        } else if (!bChangeSceneLock && byCango == 2 && !bPopUp) {
            //如果新手区没接受指定任务
            if (!GameBean.BL_NEWPLAYER_CAN_GO_LOCK || !MainLogic.getInstance().uiInterFace.sRoamMapName.equals("女娲圣域")) {
                bChangeSceneLock = true;
                this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, false, false);
                lcontinueTime = System.currentTimeMillis();
                MainLogic.getInstance().send(Constant.MSG_NET_WALK, Constant.SOCKET_MSG_TYPE_LOGIC);
            }
        }
        if ((System.currentTimeMillis() - lcontinueTime) >= 1000) {
            lcontinueTime = System.currentTimeMillis();
            MainLogic.getInstance().send(Constant.MSG_NET_WALK, Constant.SOCKET_MSG_TYPE_LOGIC);
        }
    }

    public void stopAutoRun(boolean message, boolean changeState) {
        //如果寻路中方向键寻路终止
        if (changeState) {
            this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, true, false);
        }
//#if NOKIA_S60V5
         MainLogic.getInstance().uiInterFace.clearPoint();
//#endif
        if (message) {
            MainLogic.getInstance().uiEquipment.getChatInformation(100, "", (byte) 5, "寻路已终止！");
        }
        this.clearFindPath();
        Tools.printLog("寻路已经停止");
    }

    private void autoRunchangeState() {
        try {
            //玩家死亡
            switch (this.byPlayerUpdateState) {
                case Constant.PLAYER_STATE_RUN:
                    if (byPlayerBigState != Constant.PLAYER_BIG_STATE_FIGHT) {
                        stopAutoRun(true, true);
                    } else {
                        stopAutoRun(false, true);
                    }
                    blAutoFightIndex = -1;
                    break;
                default: //改变状态
                //如果寻路开关打开重新去路径点
                //          if (this.lSpaceTime >= this.iSpeedTime)
                {
                    boolean blCanGo = true;
                    if (blCanGo) {
                        //到达当前路径点
                        if (this.blHasArrivePoint) {
                            if (this.pointSize >= 0) {
                                //移出当前路径点
                                verAutoRunPath.removeElementAt(this.pointSize);
                                //取下一个路径点
                                this.pointSize -= 1;
                            }
                            //最短路径已经走完
                            if (this.pointSize == -1) {
                                if (blHold) {
                                    return;
                                }

//                                if(getAutoRunTagPathNum() == 1)
                                {

//                                if(MainLogic.gameMap.canNotGo(this.iPlayerX , this.iPlayerY )!= 2)
//                                if(!GameBean.BL_CHANGESCENCEAUTOMOVE_LOCK)
                                    {
                                        if (this.verAutoRunPath != null) {
                                            this.verAutoRunPath.removeAllElements();
                                        }
                                        verAutoRunPath = null;
                                        this.pointSize = -1;

                                        if(blMissionFindePath)
                                        {
                                        if(Math.abs(this.iPlayerX - iTargetObjX) <16&&Math.abs(this.iPlayerY - iTargetObjY)<16)
                                        {
                                         blMissionFindePath = false;
                                        resetAutoRunTagPath(getAutoRunTagPath());
                                         }
                                        }
                                        else
                                        resetAutoRunTagPath(getAutoRunTagPath());
                                        this.clearPath();
                                        blHold = true;
//                                if(getAutoRunTagPath() == -1)
                                        this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, true, false);
                                        //#if NOKIA_S60V5
                                         MainLogic.getInstance().uiInterFace.clearPoint();
                                        //#endif
                                        if (getAutoRunTagPath() == -1) {
                                            iArrayAutoRunTagPos = null;
                                             blMissionFindePath = false;
                                            if (blAutoMoveToFight != -1) {
                                                if (playerUseSkill(blAutoMoveToFight, true, true)) {
                                                    fightReadChangeState();
                                                    blAutoMoveToFight = -1;
                                                }
                                            }
                                        }
                                    }
                                }
                                return;
                            } else {
                                //取出路径点
                                this.iAutoRunPoint = (int[]) this.verAutoRunPath.elementAt(this.pointSize);
                                Tools.printLog("取下一个路径点" + this.iAutoRunPoint[0] + "y:" + this.iAutoRunPoint[1]);
                                this.byPlayerUpdateDirection = (byte) this.iAutoRunPoint[2];
//                                Tools.printLog("playerdirection:" + this.byPlayerUpdateDirection);
                                this.changeAction(Constant.PLAYER_STATE_AUTO_RUN, this.byPlayerUpdateDirection, true, false);
                                this.blHasArrivePoint = false;
                            }
                        }
                    } //清空路径点容器
                    else {
                        this.verAutoRunPath.removeAllElements();
                        verAutoRunPath = null;
                        this.pointSize = -1;

                    }
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /*********************************************************************寻路*****************************************************************/
    //路径点容器
    public short[][] shPathPoint;
    //路径点容器入口索引
    public int iPathPointStart;
    //路径点容器出口索引
    public int iPathPointEnd;
    //四种移动方向对x和y坐标的影响
    public byte[] byDirEffectX, byDirEffectY;
    //全部完成标志
    private boolean blAllComplete;
    //搜索到第几层
    private int iLevelNow;
    //现在的移动方向
    private int iCurDirect;
    //现在的节点的父节点
    private int iBeforeNode;
    //移动方向总数
    private int iMaxDirect;
    //现在的节点
    private int iCurNode;
    //当前坐标
    private int iCurNodeX, iCurNodeY;
    //每一层最后的节点
    private int[] iLevelFootNode;
    //每一个节点的父节点
    private int[] iHeadNode;
    //每一个节点的移动方向
    private int[] iMoveDirect;
    //按节点移动后的坐标
    private int[] iNodeX, iNodeY;
    //已到过标记
    private int[][] iVisitedPoint;
    //目标点
    public static int iTargetX = -1;
    public static int iTargetY = -1;
    public static int iTargetAutoX = -1;
    public static int iTargetAutoY = -1;
    public static int iTargetObjX = -1;
    public static int iTargetObjY = -1;
    private static boolean blMissionFindePath = false;
    //路径点(0方向1x2y)
    private int[] iTempPath;
    /*
     * @param String scenceKey 目标场景key 
     * @param int objx 目标点x坐标
     * @param int objy 目标点x坐标
     */

    public void runPathFinderForMission(String scenceKey, int objx, int objy) {
        MainCanvas.clearInput();
        this.iTargetX = -1;
        this.iTargetY = -1;
        iTargetAutoX = objx;
        iTargetAutoY = objy;
       
//        blMissionFindePath = true;
//        MainLogic.getInstance().clearLockedObj(0, true);
        //本场景直接寻路
        Tools.printLog("current scence id:" + MainLogic.getInstance().uiInterFace.sRoamMapKeys
                + "scenceKey" + scenceKey + "objx:" + objx + "objy" + objy);
        if (scenceKey.equals(MainLogic.getInstance().uiInterFace.sRoamMapKeys)) {
            addAutoRunTagPath(1, 0, objx, objy);
            startAutoMovePath();
        } else {
            this.iTargetX = objx;
            this.iTargetY = objy;
             iTargetObjX = objx;
             iTargetObjY = objy;
            GameBean.BY_CMD_PLAYER_AUTORUN_CUR_SENCE = MainLogic.getInstance().uiInterFace.sRoamMapKeys;
            GameBean.BY_CMD_PLAYER_AUTORUN_OBJ_SENCE = scenceKey;
            MainLogic.getInstance().send(Constant.MSG_NET_CMD_FIND_PATH, Constant.SOCKET_MSG_TYPE_LOGIC);
        }
    }
    /**
     * @param tx int 起点x坐标
     * @param ty int 起点y坐标
     * @param targetX int 目标点x坐标
     * @param targetY int 目标点y坐标
     */
    private boolean blCanThroughtTag = false;

    public void pathFinder(int startX, int startY, int targetX, int targetY) {
        iTargetAutoX = targetX;
        iTargetAutoY = targetY;
        if (iLevelFootNode == null) {
            this.byDirEffectX = new byte[]{0, 0, -1, 1};
            this.byDirEffectY = new byte[]{-1, 1, 0, 0};
            this.iLevelFootNode = new int[2700];
            this.iHeadNode = new int[2700];
            this.iHeadNode = new int[2700];
            this.iMoveDirect = new int[2700];
            this.iNodeX = new int[2700];
            this.iNodeY = new int[2700];
            this.verAutoRunPath = new Vector(100, 10);
            this.iLevelNow = 1;
            this.iMaxDirect = 4;
        }

        try {
            this.iCurNodeX = (startX >> 4) - Map.iAreaStartxCount;
            this.iCurNodeY = (startY >> 4) - Map.iAreaStartyCount;
            this.iTargetX = (targetX >> 4) - Map.iAreaStartxCount;
            this.iTargetY = (targetY >> 4) - Map.iAreaStartyCount;
            Tools.printLog("开始寻路：开始坐标x:" + startX + "开始坐标Y:" + startY + "目标坐标x:" + targetX + "目标坐标y:" + targetY);
//            Tools.printLog("开始寻路：开始col:" + iCurNodeX + "开始Y:" + iCurNodeY + "目标坐标x:" + iTargetX + "目标坐标y:" + iTargetY);
            this.iLevelNow = 1;
            this.iLevelFootNode[1] = 0;
            this.iLevelFootNode[0] = -1;
            this.iNodeX[0] = this.iCurNodeX;
            this.iNodeY[0] = this.iCurNodeY;
            this.iVisitedPoint = new int[Map.shAreaHCount][Map.shAreaWCount];
            this.blAllComplete = false;
            this.verAutoRunPath.removeAllElements();
            boolean blTooFar = false;
            if (this.iTargetY <= Map.iblockYCount && this.iTargetX <= Map.iblockXCount) {
                if (Map.byCollisionData[this.iTargetY][this.iTargetX] == 2) {
                    blCanThroughtTag = true;
                } else {
                    blCanThroughtTag = false;
                }
            } else {
                return;
            }
            while (!this.blAllComplete) {
                //开始搜索下一层
                this.iLevelNow++;
                //新一层的尾节点先设为与上一层相同
                this.iLevelFootNode[this.iLevelNow] = this.iLevelFootNode[this.iLevelNow - 1];
                //对上一层所有节点扩展 从上一层最后节点开始搜索到当前层最后节点
                for (this.iBeforeNode = this.iLevelFootNode[this.iLevelNow - 2] + 1; this.iBeforeNode <= this.iLevelFootNode[this.iLevelNow - 1]; this.iBeforeNode++) {
                    //尝试所有方向
                    for (this.iCurDirect = 0; this.iCurDirect < this.iMaxDirect; this.iCurDirect++) {
                        //判断是否可以到达该点
                        if ((this.isCanArrive() != 0) && (!this.blAllComplete)) {
                            //移动尾指针准备加入新节点
                            this.iLevelFootNode[this.iLevelNow]++;
                            this.iCurNode = this.iLevelFootNode[this.iLevelNow];
                            //寻路算法数组越界更改
                            if (this.iCurNode >= this.iHeadNode.length) {
                                blTooFar = true;
                                break;
                            }
                            //置头指针
                            this.iHeadNode[this.iCurNode] = this.iBeforeNode;
                            //加入新节点
                            this.iMoveDirect[this.iCurNode] = this.iCurDirect;
                            this.iNodeX[this.iCurNode] = this.iCurNodeX;
                            this.iNodeY[this.iCurNode] = this.iCurNodeY;
                            //做已到过标记
                            this.iVisitedPoint[this.iCurNodeY][this.iCurNodeX] = 1;
                            //判断是否到达目标点
                            if (this.isComplete() == 1) {
                                this.blAllComplete = true;
                            }
                        }
                    }
                }
                //寻路算法数组越界更改
                if (blTooFar) {
                    break;
                }
                //当前层没有可以走的点,寻路失败
                if (this.iLevelFootNode[this.iLevelNow] == this.iLevelFootNode[this.iLevelNow - 1]) {
                    break;
                }
            }
            this.iTargetX = -1;
            this.iTargetY = -1;
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }
    /*
     * 清理路径点
     */

    public void clearPath() {
        this.iLevelFootNode = null;
        this.iHeadNode = null;
        this.iHeadNode = null;
        this.iMoveDirect = null;
        this.iNodeX = null;
        this.iNodeY = null;
        this.verAutoRunPath = null;
        this.pointSize = -1;
        iTargetAutoX = -1;
        iTargetAutoY = -1;
       
    }
    /*
     * 清理所有寻路数据
     */

    public void clearFindPath() {
        this.clearPath();
        blMissionFindePath = false;
        iArrayAutoRunTagPos = null;
    }

    /**
     * 是否是可以到达的点
     * @return int 0不可以到达1可以到达
     */
    private int isCanArrive() {
        try {
            //将到点的x,y坐标
            this.iCurNodeX = this.iNodeX[this.iBeforeNode] + this.byDirEffectX[this.iCurDirect];
            this.iCurNodeY = this.iNodeY[this.iBeforeNode] + this.byDirEffectY[this.iCurDirect];
            //x坐标出界
            if ((this.iCurNodeX >= Map.shAreaWCount) || (this.iCurNodeX < 0)) {
                Tools.printLog("x坐标出界");
                return 0;
            }
            //y坐标出界
            if ((this.iCurNodeY >= Map.shAreaHCount) || (this.iCurNodeY < 0)) {
                Tools.printLog("y坐标出界" + "iCurNodeY:" + iCurNodeY + "Map.shAreaHCount:" + Map.shAreaHCount + "iAreaStartyCount:");
                return 0;
            }
//            Tools.printLog("iCurNodeY"+iCurNodeY + "iCurNodeX:"+iCurNodeX);
            //已到过
            if (this.iVisitedPoint[this.iCurNodeY][this.iCurNodeX] != 0) {
                return 0;
            }
            //有障碍
            if (blCanThroughtTag) {
                if (Map.byCollisionData[this.iCurNodeY][this.iCurNodeX] == 1) {
                    return 0;
                }
            } else {
                if (Map.byCollisionData[this.iCurNodeY][this.iCurNodeX] != 0) {
                    return 0;
                }
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
        return 1;
    }

    private int isComplete() {
        //当前节点等于目标节点
        if ((this.iCurNodeX == this.iTargetX) && (this.iCurNodeY == this.iTargetY)) {
            int iNodeIndex = this.iCurNode;
            if (iNodeIndex != 0) {
                this.iTempPath = new int[]{
                            (this.iNodeX[iNodeIndex] + Map.iAreaStartxCount) * Constant.TITLEWIDHT, (this.iNodeY[iNodeIndex] + +Map.iAreaStartyCount) * Constant.TITLEHEIGHT, this.iMoveDirect[iNodeIndex]};
            }
//            Tools.printLog("坐标x:" + (this.iNodeX[iNodeIndex] + Map.iAreaStartxCount) * Constant.TITLEWIDHT + "目标坐标y:" + (this.iNodeY[iNodeIndex] + +Map.iAreaStartyCount) * Constant.TITLEHEIGHT);

            this.verAutoRunPath.addElement(this.iTempPath);
            while (iNodeIndex != 0) {
                iNodeIndex = this.iHeadNode[iNodeIndex];
                if (iNodeIndex == 0) {
                    break;
                }
                this.iTempPath = new int[]{
                            (this.iNodeX[iNodeIndex] + Map.iAreaStartxCount) * Constant.TITLEWIDHT, (this.iNodeY[iNodeIndex] + +Map.iAreaStartyCount) * Constant.TITLEHEIGHT, this.iMoveDirect[iNodeIndex]};


                Tools.printLog(((this.iNodeX[iNodeIndex] + Map.iAreaStartxCount) * Constant.TITLEWIDHT) + "," + ((this.iNodeY[iNodeIndex] + +Map.iAreaStartyCount) * Constant.TITLEHEIGHT));
                //添加到路径容器
                this.verAutoRunPath.addElement(this.iTempPath);
            }
            return 1;
        }
        return 0;
    }
    //到达切换点

    public boolean arrivePoint(int checkx, int checky) {
        this.blHasArrivePoint = false;
        switch (this.byPlayerDirection) {
            case Constant.PLAYER_DIRECTION_UP:
//                    if(this.iPlayerY < this.lAutoRunPoint[])
                if (checky <= this.iAutoRunPoint[1]) {
                    blHasArrivePoint = true;
                }
                break;
            case Constant.PLAYER_DIRECTION_DOWN:
                if (checky >= this.iAutoRunPoint[1]) {
                    blHasArrivePoint = true;
                }
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                if (checkx <= this.iAutoRunPoint[0]) {

                    blHasArrivePoint = true;
                }
                break;
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (checkx >= this.iAutoRunPoint[0]) {
                    blHasArrivePoint = true;
                }
                break;
        }
        if (checkx == this.iAutoRunPoint[0] && checky == this.iAutoRunPoint[1]) {
            blHasArrivePoint = true;
        }
        if (blHasArrivePoint) {
            int stepy = this.iAutoRunPoint[1] - checky;
            int stepx = this.iAutoRunPoint[0] - checkx;
            this.iPlayerX = this.iAutoRunPoint[0];
            this.iPlayerY = this.iAutoRunPoint[1];
            MainLogic.gameMap.updateMayViewXy(stepx, stepy, this.iPlayerX, this.iPlayerY);
//            this.clearPath();
        }
        return this.blHasArrivePoint;
    }

    public byte getDirection(int pointx, int pointy) {
//        Tools.printLog("playerx:" + this.iPlayerX + "playery:" + this.iPlayerY + "getdirectionx:" + pointx + "get directiony:" + pointy);
        int directx = this.iPlayerX - pointx;
        int directy = this.iPlayerY - pointy;
        //玩家在目标右边
        if (directx >= 0) {
            //玩家在目标下边
            if (directy >= 0) {
                return (directx > directy) ? Constant.PLAYER_DIRECTION_LEFT : Constant.PLAYER_DIRECTION_UP;
            } else {
                return (directx > (-directy)) ? Constant.PLAYER_DIRECTION_LEFT : Constant.PLAYER_DIRECTION_DOWN;
            }
        } else//玩家在目标左边
        {
            //玩家在目标下边
            if (directy >= 0) {
                return ((-directx) > directy) ? Constant.PLAYER_DIRECTION_RIGHT : Constant.PLAYER_DIRECTION_UP;
            } else {
                return ((-directx) > (-directy)) ? Constant.PLAYER_DIRECTION_RIGHT : Constant.PLAYER_DIRECTION_DOWN;
            }
        }
    }
//public void refreshPlayer(byte state, byte direct, int x, int y, short speed, short hp, short mp, byte msgType, byte byType, int aimId, short shCureHp, short shCureMp, int iExp, byte isDie)
//  {
//  }
    public boolean blAutoFight = false;

    private void changeState() {
        try {
            if (blAutoRunStartCheck) {
                startAutoMovePath();
                blAutoRunStartCheck = false;
                return;
            }
            //当前状态
            switch (this.byPlayerState) {
                case Constant.PLAYER_STATE_STAND: //站
                    this.standChangeState();
                    break;
                case Constant.PLAYER_STATE_RUN: //跑
                    this.runChangeState();
                    break;
                case Constant.PLAYER_STATE_AUTO_RUN: //自动寻路状态
                    this.autoRunchangeState();
                    break;
//        case Constant.PLAYER_STATE_LOCK: //锁定
//          this.lockedChangeLogic();
//          break;
                case Constant.PLAYER_STATE_FIGHT_READY: //战备
                    this.fightReadChangeState();
                    break;
                case Constant.PLAYER_STATE_FIGHT: //战斗
                    this.fightChangeState();
                    break;
            }
            this.byPlayerUpdateState = -1;
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    private int getPlayerXYStep(byte direction, byte type) {
        switch (type) {
            case 1:
                switch (direction) {
                    case Constant.PLAYER_DIRECTION_LEFT:
                        return -4;
                    case Constant.PLAYER_DIRECTION_RIGHT:
                        return 4;
                }
                break;
            case 2:
                switch (direction) {
                    case Constant.PLAYER_DIRECTION_UP:
                        return -4;
                    case Constant.PLAYER_DIRECTION_DOWN:
                        return 4;
                }
                break;
        }
        return 0;
    }
    /**
     * 站立状态改变 可变跑动，战斗准备
     */
    boolean blPlayerRun = false;

    private void standChangeState() {
        if (blNeedChangeAction) {
            this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, false, true);
            blNeedChangeAction = false;
        }
        //如果处于大攻击状态有目标则执行攻击逻辑
        if (byPlayerBigState == Constant.PLAYER_BIG_STATE_FIGHT && blAutoFightIndex != -1) {
            if (this.byPlayerState == Constant.PLAYER_STATE_STAND && MainLogic.iLockedObjNumber[0][1] != -1 && blAutoFightIndex != -1) {
                playerUseSkill(blAutoFightIndex, true, false);
            }
        }
        //角色更新状态
        switch (this.byPlayerUpdateState) {
            case Constant.PLAYER_STATE_RUN: //跑
            case Constant.PLAYER_STATE_AUTO_RUN:
                int iStepx = getPlayerXYStep(this.byPlayerUpdateDirection, (byte) 1);
                int iStepy = getPlayerXYStep(this.byPlayerUpdateDirection, (byte) 2);
                byte bCanGo = MainLogic.gameMap.canNotGo(this.iPlayerX + iStepx, this.iPlayerY + iStepy, this.byPlayerDirection);
//                System.out.println("bCanGo=" + bCanGo);
                if (bCanGo == 0) {//可以走
                    bPopUp = false;
                    this.changeAction(this.byPlayerUpdateState, this.byPlayerUpdateDirection, true, false);
                    //初始化开始走路时间
                    this.lWalkStartTime = System.currentTimeMillis();
//                Tools.printLog("this.iPlayerXstandChangeState" + this.iPlayerX);
                    blPlayerRun = true;
                } else if (bCanGo == 2) {//传送点
                    this.changeAction(this.byPlayerUpdateState, this.byPlayerUpdateDirection, true, false);
                    //初始化开始走路时间
                    this.lWalkStartTime = System.currentTimeMillis();
//                Tools.printLog("this.iPlayerXstandChangeState" + this.iPlayerX);
                    blPlayerRun = true;
                } else if (bCanGo == 1) {//不可以走(后添加的)
                    //this.lWalkStartTime = System.currentTimeMillis();
                    // blPlayerRun = this.autoChangeRun(bCanGo);
                }
                break;
            case Constant.PLAYER_STATE_FIGHT_READY: //战备
                if (MainLogic.getInstance().iLockedObjNumber[0][0] != -1) {
                    this.byPlayerDirection = getDirection((int) MainLogic.getInstance().iLockedObjNumber[0][2], (int) MainLogic.getInstance().iLockedObjNumber[0][3]);
                }
                this.changeAction(Constant.PLAYER_STATE_FIGHT, this.byPlayerDirection, true, false);
                break;
        }
    }

    private void runChangeState() {
//        if (Math.abs(this.iPlayerX - this.iPlayerOldX) >= 4 || Math.abs(this.iPlayerY - this.iPlayerOldY) >= 4)
        {
            this.iPlayerOldX = this.iPlayerX;
            this.iPlayerOldY = this.iPlayerY;
            blPlayerRun = true;
            //角色更新状态
            switch (this.byPlayerUpdateState) {
                case Constant.PLAYER_STATE_STAND: //跑
                    this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerUpdateDirection, true, false);
                    blAutoFightIndex = -1;
                    break;
                case Constant.PLAYER_STATE_FIGHT_READY: //战备
                    if (MainLogic.getInstance().iLockedObjNumber[0][0] != -1) {
                        this.byPlayerDirection = getDirection((int) MainLogic.getInstance().iLockedObjNumber[0][2], (int) MainLogic.getInstance().iLockedObjNumber[0][3]);
                    }
                    this.changeAction(Constant.PLAYER_STATE_FIGHT, this.byPlayerDirection, true, false);
                    break;
//                case Constant.PLAYER_STATE_RUN:
//                    blPlayerRun = this.autoChangeRun((byte) -1);
//                    break;
            }
        }
    }

    private void fightReadChangeState() {
        if (MainLogic.getInstance().iLockedObjNumber[0][0] != -1) {
            this.byPlayerDirection = getDirection((int) MainLogic.getInstance().iLockedObjNumber[0][2], (int) MainLogic.getInstance().iLockedObjNumber[0][3]);
        }
        this.changeAction(Constant.PLAYER_STATE_FIGHT, this.byPlayerDirection, true, false);
    }

    private void fightChangeState() {
        switch (this.byPlayerUpdateState) {
//            case Constant.PLAYER_STATE_STAND: //跑
//                this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, true, false);
//                break;
            case Constant.PLAYER_STATE_RUN: //跑
                if (byPlayerBigState == Constant.PLAYER_BIG_STATE_FIGHT) {
                    blAutoFightIndex = -1;
                }
                this.changeAction(Constant.PLAYER_STATE_RUN, this.byPlayerUpdateDirection, true, false);
                break;
        }
    }

    /**
     * 改变角色动画 发消息给服务器
     * @param state
     * @param direct
     * @param blIsSend
     * @param blOnlyChangeAni
     */
    public void changeAction(byte state, byte direct, boolean blIsSend, boolean blOnlyChangeAni) {
        try {
            //状态不变并且额方向不变不发
            if (!blOnlyChangeAni && (this.byPlayerState == state) && (this.byPlayerDirection == direct)) {
//                blIsSend = false;
                return;
            }
            blPlayerAttackOver = false;
            blStartWalk = true;
            this.lWalkContinueTime = 0;
            //跑步状态改变或者方向改变需要发时间差
            if ((this.byPlayerState == Constant.PLAYER_STATE_RUN || this.byPlayerState == Constant.PLAYER_STATE_AUTO_RUN) && blIsSend) {
                this.lWalkContinueTime = (int) (System.currentTimeMillis() - this.lWalkStartTime);
            }
            if (this.byPlayerState == Constant.PLAYER_STATE_AUTO_RUN && state == Constant.PLAYER_STATE_AUTO_RUN && !autoRunDirenctionChange(this.byPlayerDirection, direct)) {
                this.byPlayerDirection = direct;
            } else {
                this.byPlayerDirection = direct;
                switch (state) {
                    //玩家死亡
                    case Constant.PLAYER_STATE_DIE:
                        break;
                    case Constant.PLAYER_STATE_STAND:
                        switch (direct) {
                            case Constant.PLAYER_DIRECTION_UP:
                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_UP_STAND);
                                break;
                            case Constant.PLAYER_DIRECTION_DOWN:
                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_DOWN_STAND);
                                break;
                            case Constant.PLAYER_DIRECTION_LEFT:
                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_LEFT_STAND);
                                break;
                            case Constant.PLAYER_DIRECTION_RIGHT:
                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_RIGHT_STAND);
                                break;
                        }
                        break;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
//                          switch (direct) {
//                            case Constant.PLAYER_DIRECTION_UP:
//                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_UP_STAND);
//                                break;
//                            case Constant.PLAYER_DIRECTION_DOWN:
//                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_DOWN_STAND);
//                                break;
//                            case Constant.PLAYER_DIRECTION_LEFT:
//                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_LEFT_STAND);
//                                break;
//                            case Constant.PLAYER_DIRECTION_RIGHT:
//                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_RIGHT_STAND);
//                                break;
//                        }
                        switch (direct) {
                            case Constant.PLAYER_DIRECTION_UP:
                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_UP_RUN);
                                break;
                            case Constant.PLAYER_DIRECTION_DOWN:
                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_DOWN_RUN);
                                break;
                            case Constant.PLAYER_DIRECTION_LEFT:
                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_LEFT_RUN);
                                break;
                            case Constant.PLAYER_DIRECTION_RIGHT:
                                this.changeAvatarAction(Constant.PLAYER_ACTION_ID_RIGHT_RUN);
                                break;
                        }
                        break;
                    case Constant.PLAYER_STATE_FIGHT:
                        short actId = 0;
                        if (iPlayerAniId != Constant.RES_PLAYER_MAN_ANI_PATH && iPlayerAniId != Constant.RES_PLAYER_MAN_ANI_PATH) {
                            actId = Constant.PLAYER_ACTION_ID_DOWN_FIGHT;
                        } else {
                            actId = this.skillPlayer.getSkillPlayerActionId();//= this.getActID();
                        }
                        switch (direct) {
                            case Constant.PLAYER_DIRECTION_DOWN:
                                break;
                            case Constant.PLAYER_DIRECTION_UP:
                                actId += 1;
                                break;
                            case Constant.PLAYER_DIRECTION_LEFT:
                                actId += 2;
                                break;
                            case Constant.PLAYER_DIRECTION_RIGHT:
                                actId += 3;
                                break;
                        }
                        this.changeAvatarAction(actId);
                        break;
                }
            }
            //            if ((this.byRoleState == Constant.STATE_PLAYER_RUN || this.byRoleState == Constant.STATE_PLAYER_AUTO_MOVE
//                || this.byRoleState == Constant.STATE_PLAYER_AUTO_FIND_NPC) && (state == Constant.STATE_PLAYER_RUN
//                || state == Constant.STATE_PLAYER_AUTO_MOVE || state == Constant.STATE_PLAYER_AUTO_FIND_NPC))
            if (this.byPlayerState == Constant.PLAYER_STATE_RUN || state == Constant.PLAYER_STATE_RUN || this.byPlayerState == Constant.PLAYER_STATE_AUTO_RUN || state == Constant.PLAYER_STATE_AUTO_RUN) {
                this.lStartTime = this.lUpdateTime = System.currentTimeMillis();
//                Tools.printLog("开始更新动作：" + state);
//               this.lUpdateTime = System.currentTimeMillis();
                this.iMoveDistance = 0;

                if (this.byPlayerState == Constant.PLAYER_STATE_RUN || this.byPlayerState == Constant.PLAYER_STATE_AUTO_RUN) {
                    blStartWalk = false;
                }
            } else {
//                this.lUpdateTime = System.currentTimeMillis();
            }
//            //只改变动画不改变状态
            if (blOnlyChangeAni) {
                return;
            }

//            //状态改变判断是否为同一状态
//            if (byRoleState == state && byRoleState == Constant.STATE_PLAYER_STAND)
//                {
//                blIsSend = false;
//                }
            //状态改变

            this.byPlayerState = state;
//            this.lWalkTime = this.lUpdateTime;
            MainLogic.getInstance().iTimeDelay = 0;
//            //发指令
            if (blIsSend && MainLogic.blLogined) {
                if (this.byPlayerState == Constant.PLAYER_STATE_RUN
                        || this.byPlayerState == Constant.PLAYER_STATE_AUTO_RUN
                        || this.byPlayerState == Constant.PLAYER_STATE_STAND) {
                    MainLogic.getInstance().send(Constant.MSG_NET_WALK, Constant.SOCKET_MSG_TYPE_LOGIC);
                } else if (this.byPlayerState == Constant.PLAYER_STATE_FIGHT) {

                    MainLogic.getInstance().send(Constant.MSG_NET_BATTLE, Constant.SOCKET_MSG_TYPE_LOGIC);
                }
            }
            //
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }
    private int iActId = 0;

    public void setActID(int ActId) {
        this.iActId = ActId;
    }

    public int getActID() {
        return this.iActId;
    }
    /*
     * 添加tag点
     */
    //loading 后是否继续寻路
    public static boolean blAutoRunStartCheck = false;

    public static void addAutoRunTagPath(int num, int index, int tagx, int tagy) {
        Tools.printLog("添加tag点" + num + "tagx" + tagx + "tagy" + tagy);
        if (iArrayAutoRunTagPos == null) {
            iArrayAutoRunTagPos = new int[(num + 1) * 2];
            Tools.resetAniArray(-1, iArrayAutoRunTagPos);
        }
        blMissionFindePath = true;
        iArrayAutoRunTagPos[index * 2] = tagx;
        iArrayAutoRunTagPos[index * 2 + 1] = tagy;
        if (iTargetX != -1) {
            iArrayAutoRunTagPos[num * 2] = iTargetX;
            iArrayAutoRunTagPos[num * 2 + 1] = iTargetY;
        }
    }

    public static int getAutoRunTagPath() {
        if (iArrayAutoRunTagPos == null) {
            return -1;
        }
        int length = iArrayAutoRunTagPos.length;
        for (int i = 0; i < length; i++) {
            if (iArrayAutoRunTagPos[i] != -1) {
                return i;
            }
        }
        return -1;
    }

    public static int getAutoRunTagPathNum() {
        if (iArrayAutoRunTagPos == null) {
            return 0;
        }
        int nums = 0;
        int length = iArrayAutoRunTagPos.length;
        for (int i = 0; i < length; i++) {
            if (iArrayAutoRunTagPos[i] != -1) {
                nums += 1;
            }
        }
        return nums;
    }

    public static void resetAutoRunTagPath(int index) {
        if (index == -1) {
            return;
        }
        if (iArrayAutoRunTagPos == null) {
            return;
        }
        iArrayAutoRunTagPos[index] = -1;
        iArrayAutoRunTagPos[index + 1] = -1;
//         this.clearPath();
    }
    //获得路径点
    private static boolean blHold = true;

    public void startAutoMovePath() {
        //测试用
//        if (this.byPlayerState == Constant.PLAYER_STATE_AUTO_RUN) {
//            return;
//        }
        if (this.byPlayerState == Constant.PLAYER_STATE_DIE) {
            return;
        }
        if (iArrayAutoRunTagPos == null) {
            return;
        }
        if (getAutoRunTagPath() == -1) {
            clearFindPath();
            return;
        }
        pathFinder(this.iPlayerX, this.iPlayerY, iArrayAutoRunTagPos[getAutoRunTagPath()], iArrayAutoRunTagPos[getAutoRunTagPath() + 1]);
        this.pointSize = verAutoRunPath.size() - 1;
        if (this.pointSize < 0) {
            clearFindPath();
            Tools.printLog("寻路失败！！！！！");
            return;
        }
        blHold = false;
        int posx = (this.iPlayerX >> 4) * Constant.TITLEWIDHT;
        int posy = (this.iPlayerY >> 4) * Constant.TITLEHEIGHT;
        int distancex = posx - this.iPlayerX;
        int distancey = posy - this.iPlayerY;
        this.iPlayerX = posx;
        this.iPlayerY = posy;
        MainLogic.gameMap.updateMayViewXy(distancex, distancey, this.iPlayerX, this.iPlayerY);
        this.iAutoRunPoint = (int[]) this.verAutoRunPath.elementAt(this.pointSize);
        byPlayerUpdateDirection = (byte) this.iAutoRunPoint[2];
        Tools.printLog("playerdirection:" + this.byPlayerDirection + " this.iAutoRunPoint:" + this.iAutoRunPoint[0] + " this.iAutoRunPointy" + this.iAutoRunPoint[1]);
        blPlayerRun = true;
        this.changeAction(Constant.PLAYER_STATE_AUTO_RUN, this.byPlayerUpdateDirection, true, false);
        this.byPlayerUpdateState = this.byPlayerState = Constant.PLAYER_STATE_AUTO_RUN;
        this.blHasArrivePoint = false;
    }

    public boolean autoRunDirenctionChange(byte direct, byte objDirect) {
        switch (direct) {
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (objDirect == Constant.PLAYER_DIRECTION_RIGHT) {
                    return false;
                }
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                if (objDirect == Constant.PLAYER_DIRECTION_LEFT) {
                    return false;
                }
                break;
        }
        return true;
    }
    //绘制角色死亡

    public static void showPlayerDie(Graphics g, int x, int y) {
//        Tools.printLog("其他玩家死亡动画");
        if (aniPlayerGrave == null) {
            aniPlayerGrave = new int[5];
            ResManager.changeAction(ResManager.getAnimation(Constant.RES_PLAYER_GRAVE_ANI_PATH, Constant.RES_PUBLIC_FINAL), 1, 0, aniPlayerGrave);
        }
        ResManager.drawAnimation(ResManager.getAnimation(Constant.RES_PLAYER_GRAVE_ANI_PATH, Constant.RES_PUBLIC_FINAL), aniPlayerGrave, g, x, y, false);

        if (aniPlayerGrave[4] == 1) {
            ResManager.changeAction(ResManager.getAnimation(Constant.RES_PLAYER_GRAVE_ANI_PATH, Constant.RES_PUBLIC_FINAL), 1, 0, aniPlayerGrave);
        }
    }
    /**
     * 设置宠物动画
     */
    public static int iPetsAniId = -1;
    //宠物动画的坐标
    public static int iPetX = -1;
    public static int iPetY = -1;
    //宠物移动的目标位置
    public static int iPetDestX = -1;
    public static int iPetDestY = -1;
    //是否已经开始向目标方向移动了
    public boolean bStartMoveToDest = false;
    public static long lStopStartTime = 0L;
    //宠物的方向
    public static byte byPetDirection = 0;
    //宠物停留的时间
    public static int iPetStopTime = 0;
    //移动到目标点后是停留还是继续移动
    public static boolean bStandNextTime = false;
    public static byte byPetSpeed = 1;
    //宠物和角色的相对状态
    //玩家站立不动,宠物在玩家的周围智能移动 0
    //玩家站立不动，宠物还向着玩家的方向移动 1:
    //玩家移动，宠物不动  2
    //玩家移动，宠物也移动 3
    public static byte byPetStatus = 0;
    public final static int iPetMaxOffset = 30;//宠物的活动矩形半径
    public final static int iPetMinAIOffset = 10;//宠物的随机点最小间距
    public String sPetNick = null;
    public short shPetHeight = 45;
    public byte byPetHappyDegree = 0;//宠物快乐度
    public Image petTalkFrameImg = Tools.makeTransparent(ResManager.createImage(90000051), 140);
    public Image petTalkBgImg = Tools.makeTransparent(20, 60, 140, 0x989898);
    public String sPetTalk = null;
    public short shPetTalkBoxHeight;
    public int iPetTalkInterval = 60000; //宠物说话的时间间隔(包括宠说话开始到结束到下次开始说话)
    public long lLastPetTalkTime = 0;//宠物上次说话时间
    public boolean bPetTalk = false; //宠物是否在说话
    public String[] sPetTalkArry = null;
    public boolean bLoadPetAni = false;//是否需要加载宠物动画资源

    public void setPetTalk() {
        String temp = null;
        sPetTalkArry = new String[3];
        Tools.printLog("iPetsAniId=" + iPetsAniId);
        Tools.printLog("this.byPetHappyDegree=" + this.byPetHappyDegree);
        if (this.byPetHappyDegree <= 20) {
            this.deletePetsAni();
            return;
        }
        switch (this.iPetsAniId) {
            case 287:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 1, (short) 1024);
                break;
            case 288:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 2, (short) 1024);
                break;
            case 291:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 3, (short) 1024);
                break;
            case 67:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 4, (short) 1024);
                break;
            case 6:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 5, (short) 1024);
                break;
            case 290:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 6, (short) 1024);
                break;
            case 3:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 7, (short) 1024);
                break;
            case 1:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 8, (short) 1024);
                break;
            case 31:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 9, (short) 1024);
                break;
            case 294:
                temp = MainLogic.getInstance().uiInterFace.sysMessage.readTXT(Constant.RES_PET_TALK_TXT, '#', 10, (short) 1024);
                break;
            default:
                temp = null;
                break;
        }
        Tools.printLog("temp=" + temp);
        if (temp == null) {
            this.sPetTalk = null;
            this.sPetTalkArry = null;
            return;
        }
        byte byHappyType = -1;
        if (this.byPetHappyDegree >= 90 && this.byPetHappyDegree <= 100) {
            //兴奋
            byHappyType = 1;
        } else if (this.byPetHappyDegree >= 70 && this.byPetHappyDegree <= 89) {
            //快乐
            byHappyType = 2;
        } else if (this.byPetHappyDegree >= 50 && this.byPetHappyDegree <= 69) {
            //正常
            byHappyType = 3;
        } else if (this.byPetHappyDegree >= 40 && this.byPetHappyDegree <= 49) {
            //不满
            byHappyType = 4;
        } else if (this.byPetHappyDegree >= 20 && this.byPetHappyDegree <= 39) {
            //愤怒
            byHappyType = 5;
        }
        int[] iPlace = new int[14];
        int num = 0;
        int startPos = 0;
        int endPos = 0;
        for (short i = 0; i < temp.length(); i++) {
            if (temp.charAt(i) == '|') {
                iPlace[num] = i;
                num++;
            }
        }
        switch (byHappyType) {
            case 1:
                startPos = 0;
                endPos = iPlace[2];
                break;
            case 2:
                startPos = iPlace[2] + 1;
                endPos = iPlace[5];
                break;
            case 3:
                startPos = iPlace[5] + 1;
                endPos = iPlace[8];
                break;
            case 4:
                startPos = iPlace[8] + 1;
                endPos = iPlace[11];
                break;
            case 5:
                startPos = iPlace[11] + 1;
                endPos = temp.length() - 1;
                break;
        }
        iPlace = null;
        Tools.printLog("startPos=" + startPos + "#endPos=" + endPos);
        temp = temp.substring(startPos, endPos);
        Tools.printLog("temp=" + temp);
        num = temp.indexOf('|');
        sPetTalkArry[0] = temp.substring(0, num);
        temp = temp.substring(num + 1);
        num = temp.indexOf('|');
        sPetTalkArry[1] = temp.substring(0, num);
        sPetTalkArry[2] = temp.substring(num + 1);
        for (byte i = 0; i < 3; i++) {
            Tools.printLog("sPetTalkArry[" + i + "]=" + sPetTalkArry[i]);
        }
        this.sPetTalk = sPetTalkArry[Tools.random(0, 2)];
        Tools.printLog("this.sPetTalk=" + this.sPetTalk);
        temp = null;
        this.shPetTalkBoxHeight = (short) (Tools.getParagraphHeight(sPetTalk, 97, Constant.FONT_SMALL_HEIGHT) + 8);
    }

    /**
     * 添加溜宠
     * @param aniid
     * @param shHeight
     * @param sPetName
     * @param byPetHappyDegree 
     */
    public void addPetsAni(int aniid, short shHeight, String sPetName, byte byPetHappyDegree) {
        Tools.printLog("aniid=" + aniid + "#" + "shHeight=" + shHeight + "#" + "sPetName=" + sPetName + "byPetHappyDegree=" + byPetHappyDegree);
        if (aniid != -1) {
            if (byPetHappyDegree <= 20) {
                this.deletePetsAni();
                return;
            }
            iPetsAniId = aniid;
            bStartMoveToDest = false;
            this.bStandNextTime = false;
            lStopStartTime = System.currentTimeMillis();
            iPetStopTime = Tools.random(3000, 10000);
            this.byPetDirection = this.byPlayerDirection;
            this.iPetX = this.iPlayerX + iPetMaxOffset;
            this.iPetY = this.iPlayerY;
            this.byPetStatus = 0;
            this.byPetSpeed = 1;
            this.shPetHeight = shHeight;
            this.byPetHappyDegree = byPetHappyDegree;
            this.sPetNick = sPetName;
            setPetTalk();
            lLastPetTalkTime = System.currentTimeMillis();
            this.bPetTalk = true;
            petTalkFrameImg = Tools.makeTransparent(ResManager.createImage(90000051), 140);
            petTalkBgImg = Tools.makeTransparent(105, 10, 140, 0x989898);
            ResManager.loadAnimation(iPetsAniId, Constant.RES_PUBLIC_ONEROOM, true);
            this.bLoadPetAni = false;
            Tools.printLog("this.shPetHeight=" + this.shPetHeight);
            Tools.printLog("this.sPetTalk=" + this.sPetTalk);
            Tools.printLog("this.iPetAni=" + this.iPetsAniId);
            Tools.printLog("this.byPetHappyDegree" + this.byPetHappyDegree);
        }
    }

    /**
     * 绘制宠物说话
     */
    public void drawPetTalk(Graphics g, int x, int y) {
        if (this.iPetsAniId == -1 && this.sPetTalkArry == null) {
            return;
        }
        if (!bPetTalk) {
            if (System.currentTimeMillis() - lLastPetTalkTime > iPetTalkInterval) {
                lLastPetTalkTime = System.currentTimeMillis();
                this.bPetTalk = true;
                this.sPetTalk = sPetTalkArry[Tools.random(0, 2)];
                this.shPetTalkBoxHeight = (short) (Tools.getParagraphHeight(sPetTalk, 97, Constant.FONT_SMALL_HEIGHT) + 8);
                Tools.printLog("this.sPetTalk=" + this.sPetTalk);
                Tools.printLog("this.iPetAni=" + this.iPetsAniId);
                Tools.printLog("this.byPetHappyDegree" + this.byPetHappyDegree);
            } else {
                return;
            }
        } else {
            //说话中
            if (System.currentTimeMillis() - lLastPetTalkTime > 5000) {
                this.bPetTalk = false;
                return;
            }
        }
        //Tools.printLog(this.sPetTalk);
        //根据宠物的位置来决定宠物说话的位置
        //在宠物左上方，右上方，正上方
        int iOffsetX = iPetX - x;
        //根据宠物的位置来决定宠物说话的位置
        //在宠物左上方，右上方，正上方
        if (iOffsetX <= 80) {
            //右上方
            g.drawRegion(petTalkFrameImg, 32, 0, 9, 9, Constant.TRANS_ROT90, iOffsetX + 10 - 4, this.iPetY - y - shPetHeight - Constant.FONT_SMALL_HEIGHT, 0);
            Tools.drawRoundRect(g, petTalkFrameImg, petTalkBgImg, (byte) 2, 105, shPetTalkBoxHeight, iOffsetX + 10, this.iPetY - y - shPetHeight - Constant.FONT_SMALL_HEIGHT - this.shPetTalkBoxHeight);
            Tools.drawParagraph(g, iOffsetX + 14, this.iPetY - y + 5 - shPetHeight - Constant.FONT_SMALL_HEIGHT - this.shPetTalkBoxHeight, 97, sPetTalk, 0x000000, Constant.FONT_SMALL_HEIGHT, -1);
            //绘制内容
        } else if (iOffsetX >= 160) {
            //左上方
            g.drawRegion(petTalkFrameImg, 32, 0, 9, 9, Constant.TRANS_NONE, iOffsetX - 10 - 9, this.iPetY - y - shPetHeight - Constant.FONT_SMALL_HEIGHT, 0);
            Tools.drawRoundRect(g, petTalkFrameImg, petTalkBgImg, (byte) 2, 105, this.shPetTalkBoxHeight, iOffsetX - 115, this.iPetY - y - shPetHeight - this.shPetTalkBoxHeight - Constant.FONT_SMALL_HEIGHT);
            Tools.drawParagraph(g, iOffsetX - 111, this.iPetY - y + 5 - shPetHeight - this.shPetTalkBoxHeight - Constant.FONT_SMALL_HEIGHT, 105, sPetTalk, 0x000000, Constant.FONT_SMALL_HEIGHT, -1);
        } else {
            //正上方
            g.drawRegion(petTalkFrameImg, 32, 0, 9, 9, Constant.TRANS_NONE, iOffsetX, this.iPetY - y - shPetHeight - Constant.FONT_SMALL_HEIGHT, 0);
            Tools.drawRoundRect(g, petTalkFrameImg, petTalkBgImg, (byte) 2, 105, this.shPetTalkBoxHeight, iOffsetX - 52, this.iPetY - y - shPetHeight - this.shPetTalkBoxHeight - Constant.FONT_SMALL_HEIGHT);
            Tools.drawParagraph(g, iOffsetX - 48, this.iPetY - y + 5 - shPetHeight - this.shPetTalkBoxHeight - Constant.FONT_SMALL_HEIGHT, 97, sPetTalk, 0x000000, Constant.FONT_SMALL_HEIGHT, -1);
        }
    }

    /**
     * 删除宠物
     */
    public void deletePetsAni() {
        iPetsAniId = -1;
        this.iPetX = -1;
        this.iPetY = -1;
        this.byPetDirection = 0;
        this.sPetTalk = null;
        this.petTalkBgImg = null;
        this.petTalkFrameImg = null;
        this.shPetTalkBoxHeight = 0;
        this.sPetTalkArry = null;
        ResManager.clearRes(90000051, Constant.RES_PUBLIC_FINAL, Constant.RES_TYPE_IMAGE);
    }

    /**
     * 不同状态下宠物的移动
     * @param Direction 移动方向 
     */
    public void petMove(byte Direction) {
        boolean bChange = false;
        switch (Direction) {
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (this.iPetDestX > this.iPetX) {
                    //向右走路中
                    this.iPetX += byPetSpeed;
                } else {
                    this.iPetX = this.iPetDestX;
                    //向右走停止,判读是否需要寻找下个目标点
                    if (this.iPetDestY == this.iPetY) {
                        bChange = true;
                    } else {
                        //改变方向
                        this.changePetDirection((byte) 2);
                    }
                }
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                //"向左走/
                if (this.iPetDestX < this.iPetX) {
                    //向左走路中/
                    this.iPetX -= byPetSpeed;
                } else {
                    //向左走停止,改变方向/
                    //判读是否需要寻找下个目标点
                    this.iPetX = this.iPetDestX;
                    if (this.iPetDestY == this.iPetY) {
                        bChange = true;
                    } else {
                        this.changePetDirection((byte) 2);
                    }
                }
                break;
            case Constant.PLAYER_DIRECTION_DOWN:
                //向下走
                if (this.iPetDestY > this.iPetY) {
                    //向下走路中
                    this.iPetY += byPetSpeed;
                } else {
                    //向下走路停止,寻找下个目标点
                    this.iPetY = this.iPetDestY;
                    if (this.iPetDestX == this.iPetX) {
                        bChange = true;
                    } else {
                        this.changePetDirection((byte) 1);
                    }
                }
                break;
            case Constant.PLAYER_DIRECTION_UP:
                //向上走
                if (this.iPetDestY < this.iPetY) {
                    //向上走路中
                    this.iPetY -= byPetSpeed;
                } else {
                    //向上走路停止,寻找下个目标点
                    this.iPetY = this.iPetDestY;
                    if (this.iPetDestX == this.iPetX) {
                        bChange = true;
                    } else {
                        this.changePetDirection((byte) 1);
                    }
                }
                break;
        }
        if (bChange) {
            switch (this.byPetStatus) {
                case 0:
                    this.setNextRodamPlace();
                    break;
                case 1:
                    this.initPetStatus();
                    break;
                case 2:
                    break;
                case 3:
                    this.getTransXY();
                    break;
            }
        }
    }

    /**
     * 更新宠物状态和坐标
     */
    public void updatePetShow() {
        //先考虑玩家站立不动的状态下的情况
        if (this.iPetsAniId == -1) {
            return;
        }
        if (this.bLoadPetAni) {
            ResManager.loadAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM, true);
            this.bLoadPetAni = false;
        }
        if (MainCanvas.fps > 0) {
            this.byPetSpeed = (byte) (shPlayerSpeed / MainCanvas.fps);
        } else {
            this.byPetSpeed = 2;
        }
        switch (this.byPetStatus) {
            case 0:
                //玩家站立不动,宠物在玩家的周围智能移动 0
                if (!bStartMoveToDest) {
                    //逗留时间段
                    if (System.currentTimeMillis() - lStopStartTime > iPetStopTime) {
                        //寻找下个目标点或是继续停留
                        this.setNextRodamPlace();
                    }
                    //停留中
                } else {
                    this.petMove(this.byPetDirection);
                }
                break;
            case 1:
            //玩家站立不动，宠物还向着玩家的方向移动 1:
            //this.petMove(this.byPetDirection);
            //break;
            case 3:
                //玩家移动，宠物也移动 3
                //先判读玩家和宠物的方向距离
                this.petMove(this.byPetDirection);
                break;
            case 2:
                //玩家移动，宠物不动  2
                //不用操作
                break;
        }
        this.updatePetSatus();
    }

    /**
     * 设置下次的随机地址
     */
    public void setNextRodamPlace() {
        if (this.bStandNextTime) {
            bStartMoveToDest = false;
            lStopStartTime = System.currentTimeMillis();
            iPetStopTime = Tools.random(3000, 5000);
            this.bStandNextTime = Tools.random(0, 1) == 1 ? true : false;
            this.chanagePetAction(this.byPetDirection, (byte) 0);
        } else {
            bStartMoveToDest = true;
            lStopStartTime = 0L;
            //下个目标点位置
            this.iPetDestX = Tools.getNpcRodamXY(this.iPlayerX, this.iPetX, iPetMaxOffset, iPetMinAIOffset);
            this.iPetDestY = Tools.getNpcRodamXY(this.iPlayerY, this.iPetY, iPetMaxOffset, iPetMinAIOffset);
            this.bStandNextTime = Tools.random(0, 1) == 1 ? true : false;
            //下次是停留还是继续移动
            //改变宠物的状态
            //根据xy哪个距离短就开始走哪个
            if (Math.abs(this.iPetDestX - this.iPetX) >= Math.abs(this.iPetDestY - this.iPetY)) {
                this.changePetDirection((byte) 1);
            } else {
                this.changePetDirection((byte) 2);
            }
        }
    }

    public void chanagePetAction(byte byDirection, byte state) {
        this.byPetDirection = byDirection;
        switch (byDirection) {
            case Constant.PLAYER_DIRECTION_DOWN:
                if (state == 0) {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_DOWN_STAND, 0, this.iNpcAniPre[5]);
                } else {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_DOWN_RUN, 0, this.iNpcAniPre[5]);
                }
                break;
            case Constant.PLAYER_DIRECTION_UP:
                if (state == 0) {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_UP_STAND, this.byPetDirection, this.iNpcAniPre[5]);
                } else {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_UP_RUN, this.byPetDirection, this.iNpcAniPre[5]);
                }
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                if (state == 0) {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_LEFT_STAND, this.byPetDirection, this.iNpcAniPre[5]);
                } else {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_LEFT_RUN, this.byPetDirection, this.iNpcAniPre[5]);
                }
                break;
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (state == 0) {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_RIGHT_STAND, this.byPetDirection, this.iNpcAniPre[5]);
                } else {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_RIGHT_RUN, this.byPetDirection, this.iNpcAniPre[5]);
                }
                break;
        }
    }

    /**
     * 改变宠物走路的方向
     */
    public void changePetDirection(byte byDirection) {
        //改变宠物移动的方向 
        switch (byDirection) {
            case 1:
                if (this.iPetDestX >= this.iPetX) {
                    this.chanagePetAction(Constant.PLAYER_DIRECTION_RIGHT, (byte) 1);
                } else {
                    this.chanagePetAction(Constant.PLAYER_DIRECTION_LEFT, (byte) 1);
                }
                break;
            case 2:
                if (this.iPetDestY >= this.iPetY) {
                    this.chanagePetAction(Constant.PLAYER_DIRECTION_DOWN, (byte) 1);
                } else {
                    this.chanagePetAction(Constant.PLAYER_DIRECTION_UP, (byte) 1);
                }
                break;
        }
    }

    public void initPetStatus() {
        switch (this.byPetStatus) {
            case 0:
                // Tools.printLog("宠物状态更新为:" + this.byPetStatus);
                this.bStandNextTime = false;
                this.setNextRodamPlace();
                break;
            case 1:
                //Tools.printLog("宠物状态更新为:" + this.byPetStatus);
                this.iPetDestX = this.iPlayerX;
                this.iPetDestY = this.iPlayerY;
                if (Math.abs(this.iPetDestX - this.iPetX) >= Math.abs(this.iPetDestY - this.iPetY)) {
                    this.changePetDirection((byte) 1);
                } else {
                    this.changePetDirection((byte) 2);
                }
                break;
            case 2:
                //Tools.printLog("宠物状态更新为:" + this.byPetStatus);
                this.chanagePetAction(this.byPlayerDirection, (byte) 0);
                break;
            case 3:
                // Tools.printLog("宠物状态更新为:" + this.byPetStatus);
                this.getTransXY();
                break;

        }
    }

    /**
     * 更新宠物的状态
     */
    public void updatePetSatus() {
        int length = Tools.square(this.iPetX - this.iPlayerX) + Tools.square(this.iPetY - this.iPlayerY);
        int iMaxLength = 25600;
        if (length > iMaxLength) {
            //如果宠物离人的距离太远，就瞬移到人物背后
            this.byPetDirection = this.byPlayerDirection;
            switch (this.byPlayerDirection) {
                case Constant.PLAYER_DIRECTION_DOWN:
                    this.iPetX = this.iPlayerY;
                    this.iPetY = this.iPlayerY - (this.iPetMaxOffset - 5);
                    break;
                case Constant.PLAYER_DIRECTION_UP:
                    this.iPetX = this.iPlayerX;
                    this.iPetY = this.iPlayerY + (this.iPetMaxOffset - 5);
                    break;
                case Constant.PLAYER_DIRECTION_LEFT:
                    this.iPetX = this.iPlayerX + (this.iPetMaxOffset - 5);
                    this.iPetY = this.iPlayerY;
                    break;
                case Constant.PLAYER_DIRECTION_RIGHT:
                    this.iPetX = this.iPlayerX - (this.iPetMaxOffset - 5);
                    this.iPetY = this.iPlayerY;
                    break;
            }
            this.byPetStatus = 2;
            this.initPetStatus();
            return;
        }
        //宠物状态的改变
        switch (this.byPetStatus) {
            case 0:
                //玩家站立不动,宠物在玩家的周围智能移动 0
                switch (this.byPlayerState) {
                    case Constant.PLAYER_STATE_STAND:
                    case Constant.PLAYER_STATE_FIGHT:
                    case Constant.PLAYER_STATE_FIGHT_READY:
                        //状态没有发生变化
                        return;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
                        //玩家开始移动
                        if (length >= this.iPetMaxOffset) {
                            this.byPetStatus = 3;
                            this.initPetStatus();
                        } else {
                            this.byPetStatus = 2;
                            this.initPetStatus();
                        }
                        break;
                }
                break;
            case 1:
                //玩家站立不动，宠物还向着玩家的方向移动 1:
                switch (this.byPlayerState) {
                    case Constant.PLAYER_STATE_STAND:
                    case Constant.PLAYER_STATE_FIGHT:
                    case Constant.PLAYER_STATE_FIGHT_READY:
                        //状态没有发生变化
                        if (length < this.iPetMaxOffset) {
                            this.byPetStatus = 0;
                            this.initPetStatus();
                        } else {
                            //不做变化
                        }
                        break;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
                        //玩家开始移动
                        if (length >= this.iPetMaxOffset) {
                            this.byPetStatus = 3;
                            this.initPetStatus();
                        } else {
                            this.byPetStatus = 2;
                            this.initPetStatus();
                        }
                        break;
                }
                break;
            case 2:
                //玩家移动，宠物不动  2
                switch (this.byPlayerState) {
                    case Constant.PLAYER_STATE_STAND:
                    case Constant.PLAYER_STATE_FIGHT:
                    case Constant.PLAYER_STATE_FIGHT_READY:
                        //状态没有发生变化
                        if (length < this.iPetMaxOffset) {
                            this.byPetStatus = 0;
                            this.initPetStatus();
                        } else {
                            this.byPetStatus = 1;
                            this.initPetStatus();
                        }
                        return;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
                        if (length >= this.iPetMaxOffset) {
                            this.byPetStatus = 3;
                            this.initPetStatus();
                        } else {
                            //不做改变
                            //this.byPetStatus = 2;
                        }
                        break;
                }
                break;
            case 3:
                //玩家移动，宠物也移动 3
                switch (this.byPlayerState) {
                    case Constant.PLAYER_STATE_STAND:
                    case Constant.PLAYER_STATE_FIGHT:
                    case Constant.PLAYER_STATE_FIGHT_READY:
                        //状态没有发生变化
                        if (length < this.iPetMaxOffset) {
                            this.byPetStatus = 0;
                            this.initPetStatus();
                        } else {
                            this.byPetStatus = 1;
                            this.initPetStatus();
                        }
                        return;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
                        //不做变化
                        break;
                }
                break;
        }
    }

    /**
     * 获得宠物和玩家中间的一个点
     * @param iCurrX
     * @param iCurrY
     * @param terminalX
     * @param terminalY
     */
    public void getTransXY() {
        if (this.iPetX > this.iPlayerX) {
            //向右
            this.iPetDestX = this.iPetX - Math.abs(this.iPlayerX - this.iPetX) / 3;
        } else {
            this.iPetDestX = this.iPetX + Math.abs(this.iPlayerX - this.iPetX) / 3;
        }
        if (this.iPetY > this.iPlayerY) {
            //向右
            this.iPetDestY = this.iPetY - Math.abs(this.iPlayerY - this.iPetY) / 3;
        } else {
            this.iPetDestY = this.iPetY + Math.abs(this.iPlayerY - this.iPetY) / 3;
        }
        //根据xy哪个距离短就开始走哪个
        if (Math.abs(this.iPetDestX - this.iPetX) >= Math.abs(this.iPetDestY - this.iPetY)) {
            this.changePetDirection((byte) 1);
        } else {
            this.changePetDirection((byte) 2);
        }
    }

    public void changeAvatarAction(int act) {
        ResManager.changeAction(ResManager.getAnimation(iPlayerAniId, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), act, 0, this.iNpcAniPre[0]);
        ResManager.changeAction(ResManager.getAnimation(aniAvatarShoes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), act, 0, this.iNpcAniPre[1]);
        ResManager.changeAction(ResManager.getAnimation(aniAvatarTrousers, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), act, 0, this.iNpcAniPre[2]);
        ResManager.changeAction(ResManager.getAnimation(aniAvatarCloes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), act, 0, this.iNpcAniPre[3]);
        ResManager.changeAction(ResManager.getAnimation(aniAvatarHear, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), act, 0, this.iNpcAniPre[6]);
        ResManager.changeAction(ResManager.getAnimation(aniAvatarHead, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), act, 0, this.iNpcAniPre[7]);
        ResManager.changeAction(ResManager.getAnimation(aniAvatarVeapon, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), act, 0, this.iNpcAniPre[4]);

    }

    public boolean showAvatarAction(boolean blcontinue, Graphics g, int x, int y) {
        if (!blcontinue && this.iNpcAniPre[0][4] == 1) {
            this.changeAction(Constant.PLAYER_STATE_STAND, this.byPlayerDirection, true, false);
            blPlayerAttackOver = true;
        }
        if (iPlayerAniId != Constant.RES_PLAYER_MAN_ANI_PATH && iPlayerAniId != Constant.RES_PLAYER_WOMEN_ANI_PATH) {
            return ResManager.drawAnimation(ResManager.getAnimation(iPlayerAniId, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[0], g, x, y, blcontinue);
        } else {
            if (this.iplayerOccupation == Constant.PLAYER_OCCUPTION_MASTER && (this.byPlayerDirection == Constant.PLAYER_DIRECTION_LEFT || this.byPlayerDirection == Constant.PLAYER_DIRECTION_RIGHT)) {
                if (this.byPlayerState == Constant.PLAYER_STATE_RUN || this.byPlayerState == Constant.PLAYER_STATE_STAND || this.byPlayerState == Constant.PLAYER_STATE_AUTO_RUN)//
                {
                    return (ResManager.drawAnimation(ResManager.getAnimation(aniAvatarVeapon, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[4], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(iPlayerAniId, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[0], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarShoes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[1], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarTrousers, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[2], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHear, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[6], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHead, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[7], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarCloes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[3], g, x, y, blcontinue));
                }
                return (ResManager.drawAnimation(ResManager.getAnimation(iPlayerAniId, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[0], g, x, y, blcontinue)
                        || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarShoes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[1], g, x, y, blcontinue)
                        || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarTrousers, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[2], g, x, y, blcontinue)
                        || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHear, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[6], g, x, y, blcontinue)
                        || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHead, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[7], g, x, y, blcontinue)
                        || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarCloes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[3], g, x, y, blcontinue)
                        || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarVeapon, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[4], g, x, y, blcontinue));
            } else {
                if ((this.byPlayerState == Constant.PLAYER_STATE_RUN || this.byPlayerState == Constant.PLAYER_STATE_STAND || this.byPlayerState == Constant.PLAYER_STATE_AUTO_RUN) && this.byPlayerDirection != Constant.PLAYER_DIRECTION_UP) {
                    return (ResManager.drawAnimation(ResManager.getAnimation(aniAvatarVeapon, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[4], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(iPlayerAniId, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[0], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarShoes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[1], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarCloes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[3], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarTrousers, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[2], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHear, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[6], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHead, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[7], g, x, y, blcontinue));
                } else {
                    return (ResManager.drawAnimation(ResManager.getAnimation(iPlayerAniId, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[0], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarShoes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[1], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarCloes, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[3], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarTrousers, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[2], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHear, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[6], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHead, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[7], g, x, y, blcontinue)
                            || ResManager.drawAnimation(ResManager.getAnimation(aniAvatarVeapon, GameBean.BL_PLAYER_ENTER_CENCE ? Constant.RES_PUBLIC_FINAL : Constant.RES_PUBLIC_TEMP), this.iNpcAniPre[4], g, x, y, blcontinue));
                }
            }

        }
    }
    /*
     * 玩家攻击动作是否结束in
     */
    public static boolean blPlayerAttackOver = false;

    public boolean ifPlayerAttackOver() {
        return blPlayerAttackOver;
    }
    /*
     * 玩家使用技能
     */
    private static int blAutoMoveToFight = -1;
    public static int blAutoFightIndex = -1;
    public static long lPlayerUseSkill = 0L;
    public static long lPlayerCoolSkill = 0L;

    public boolean playerUseSkill(int index, boolean ifAutoMove, boolean shownote) {
        //如果距离太远自动寻路到目标点然后使用技能攻击
        if (MainLogic.iLockedObjNumber[0][1] != -1 && (((MainLogic.iLockedObjNumber[0][2] >> 4) - (iTargetAutoX >> 4)) < 1 && ((MainLogic.iLockedObjNumber[0][2] >> 4) - (iTargetAutoX >> 4)) > -1) && (((MainLogic.iLockedObjNumber[0][3] >> 4) - (iTargetAutoY >> 4))) < 1 && ((MainLogic.iLockedObjNumber[0][3] >> 4) - (iTargetAutoY >> 4)) > -1) {
            return false;
        }
        stopAutoRun(false, false);
        blAutoFightIndex = index;
        if (GameBean.BL_PLAYER_HANGUP) {
            shownote = false;
        }
        //如果剩余蓝量不够
        if (this.iPlayerMP < iPlayerSkillUseMp[index]) {
            if (shownote) {
                if (lPlayerUseSkill == 0 || (System.currentTimeMillis() - lPlayerUseSkill) > 2000) {
                    lPlayerUseSkill = System.currentTimeMillis();
                    MainLogic.getInstance().uiEquipment.getChatInformation(100, "", (byte) 5, "精气不够！无法使用技能");
                }
            }
            return true;
        } //如果锁定类型不对
        else if (bySkillType[index] == Constant.SKILL_USE_TYPE_TEAM && MainLogic.iLockedObjNumber[0][1] != -1) {
            if (byPlayerSkillType[index] == Constant.SKILL_USE_TYPE_ONE
                    && (MainLogic.iLockedObjNumber[0][4] != Constant.LOCKED_TYPE_OTHERPLAYER
                    || UiInterFace.team.getMemberPos(MainLogic.iLockedObjNumber[0][0]) == -1)) {
                if (shownote) {
                    MainLogic.getInstance().uiEquipment.getChatInformation(100, "", (byte) 5, "无效的释放目标！");
                }
                return true;
            }
        } else if (bySkillType[index] == Constant.SKILL_USE_TYPE_ENEMY && MainLogic.iLockedObjNumber[0][1] != -1) {
            if (MainLogic.iLockedObjNumber[0][4] == Constant.LOCKED_TYPE_OTHERPLAYER && UiInterFace.team.getMemberPos(MainLogic.iLockedObjNumber[0][0]) != -1) {
                if (shownote) {
                    MainLogic.getInstance().uiEquipment.getChatInformation(100, "", (byte) 5, "无效的释放目标！");
                }
                return true;
            }
//            else if (MainLogic.iLockedObjNumber[0][4] == Constant.LOCKED_TYPE_NPC
//                    && MainLogic.getInstance().gameNpcArray.shNpcTypes[(short) MainLogic.iLockedObjNumber[0][1]] == Constant.NPC_TYPE_CANNOTATTACK) {
//                if (shownote) {
//                    MainLogic.getInstance().uiEquipment.getChatInformation(100, "", (byte) 5, "无效的释放目标！");
//                }
//                return true;
//            }
        }
        //如果冷却时间不够
        if (iPlayerSkillStartTime[index] != -1) {
            if (shownote) {
                if (lPlayerCoolSkill == 0 || (System.currentTimeMillis() - lPlayerCoolSkill) > 4000) {
                    lPlayerCoolSkill = System.currentTimeMillis();
                    MainLogic.getInstance().uiEquipment.getChatInformation(100, "", (byte) 5, "该技能冷却中，无法使用！");
                }
            }
            return true;
        }
        if (ifAutoMove && Tools.getDistance(this.iPlayerX, this.iPlayerY, (int) MainLogic.iLockedObjNumber[0][2], (int) MainLogic.iLockedObjNumber[0][3]) > iPlayerSkillDistance[index] * iPlayerSkillDistance[index]) {
            //找到相近的目标点
            //寻路并且攻击开关打开
            getGoodXY((int) MainLogic.iLockedObjNumber[0][2], (int) MainLogic.iLockedObjNumber[0][3]);
            addAutoRunTagPath(1, 0, autoAttackMonstorX, autoAttackMonstorY);
            startAutoMovePath();
            blAutoMoveToFight = index;
            return false;
        }
        if (MainLogic.iLockedObjNumber[0][4] == Constant.LOCKED_TYPE_NPC
                && MainLogic.getInstance().gameNpcArray.shNpcTypes[(short) MainLogic.iLockedObjNumber[0][1]] == Constant.NPC_TYPE_CANNOTATTACK) {
//            if (MainLogic.touchLockedObj_npcid[2] >= iPlayerX - MainLogic.iLockedNPCW
//                    && MainLogic.touchLockedObj_npcid[2] <= iPlayerX + MainLogic.iLockedNPCW
//                    && (MainLogic.touchLockedObj_npcid[3] >= iPlayerY - MainLogic.iLockedNPCH
//                    && MainLogic.touchLockedObj_npcid[3] <= iPlayerY + MainLogic.iLockedNPCH)) {
            if (MainLogic.oncetouch && Tools.getDistance(this.iPlayerX, this.iPlayerY, (int) MainLogic.iLockedObjNumber[0][2], (int) MainLogic.iLockedObjNumber[0][3]) < iPlayerSkillDistance[index] * iPlayerSkillDistance[index]) {
                MainLogic.getInstance().playerFightLogic((byte) 99, false);
//                System.out.println("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
            }
            return false;
        } else {

            int jobSkillIndex = SkillManager.getSkillIndex(Integer.parseInt(strPlayerSkill[index]));
            Tools.printLog("jobSkillIndex:" + jobSkillIndex + ",Player.strPlayerSkill[index]:" + strPlayerSkill[index] + ",Player.byPlayerSkillType[index]:" + Player.byPlayerSkillType[index] + ",gamePlayer.iPlayerSkillId[index]:" + this.iPlayerSkillId[index]);
            this.skillPlayer.setSkillKeyIndex((jobSkillIndex != -1) ? jobSkillIndex : index);
            this.skillPlayer.setSkillActionKey(strPlayerSkill[index]);
            this.skillPlayer.setSkillActionType(byPlayerSkillType[index]);
            this.skillPlayer.setSkillActionId((jobSkillIndex != -1) ? SkillManager.iSkillActJobAct[jobSkillIndex] : this.iPlayerSkillId[index]);
            this.skillPlayer.setSkillPlayerActionId(this.shPlayerSkillActId[index]);
            setPlayerSkillCDTime(index);
            this.byPlayerUpdateState = Constant.PLAYER_STATE_FIGHT_READY;
            return true;
        }
    }
    private int autoAttackMonstorX = 0;
    private int autoAttackMonstorY = 0;

    public void getGoodXY(int x, int y) {
        autoAttackMonstorX = x;
        autoAttackMonstorY = y;
        int distancex = x - this.iPlayerX;
        int distancey = y - this.iPlayerY;
        int dir = 0;
        if (distancex > 0 && distancey > 0) {
            //取左右方向
            if (distancex > distancey) {
                dir = Constant.PLAYER_DIRECTION_RIGHT;
            } else //取上下方向
            {
                dir = Constant.PLAYER_DIRECTION_DOWN;
            }
        } else if (distancex > 0 && distancey < 0) {
            //取左右方向
            if (distancex > -distancey) {
                dir = Constant.PLAYER_DIRECTION_RIGHT;
            } else //取上下方向
            {
                dir = Constant.PLAYER_DIRECTION_UP;
            }
        } else if (distancex < 0 && distancey < 0) {
            //取左右方向
            if (-distancex > -distancey) {
                dir = Constant.PLAYER_DIRECTION_LEFT;
            } else //取上下方向
            {
                dir = Constant.PLAYER_DIRECTION_UP;
            }
        } else if (distancex < 0 && distancey > 0) {
            //取左右方向
            if (-distancex > distancey) {
                dir = Constant.PLAYER_DIRECTION_LEFT;
            } else //取上下方向
            {
                dir = Constant.PLAYER_DIRECTION_DOWN;
            }
        }
        byte step = 0;
        switch (dir) {
            case Constant.PLAYER_DIRECTION_LEFT:
                autoAttackMonstorX += 16;
//                blcango = MainLogic.gameMap.canNotGo(this.iPlayerX + step, this.iPlayerY, this.byPlayerDirection);
                break;
            case Constant.PLAYER_DIRECTION_RIGHT:
                autoAttackMonstorX -= 16;
//                  blcango = MainLogic.gameMap.canNotGo(this.iPlayerX + 32, this.iPlayerY, this.byPlayerDirection);
                break;
            case Constant.PLAYER_DIRECTION_DOWN:
                autoAttackMonstorY -= 16;
                break;
            case Constant.PLAYER_DIRECTION_UP:
                autoAttackMonstorY += 16;
                break;
        }
        if (MainLogic.gameMap.canNotGo(autoAttackMonstorX, autoAttackMonstorY, this.byPlayerDirection) == 0) {
            return;
        } else {
            autoAttackMonstorX = x;
            autoAttackMonstorY = y;
        }
    }
    /*
     * 存储技能冷却时间 21101
     */

    public void saveSkillCoolTime() {
        if (iPlayerSkillCoolTime == null) {
            return;
        }
//        for(int i = 0; i < iPlayerSkillCoolTime.length; i++)
//        {
//            if(iPlayerSkillCoolTime[i] >= 600)
//        }
//         iPlayerSkillCoolTime = new int[nums];
//            iPlayerSkillStartTime = new long[nums];
    }

    public boolean autoChangeRun(byte byCango) {
        if (byCango == 0 || byCango == 2) {
            return false;
        } else if (byCango == -1) {
            int iStepx = getPlayerXYStep(this.byPlayerUpdateDirection, (byte) 1);
            int iStepy = getPlayerXYStep(this.byPlayerUpdateDirection, (byte) 2);
            byte bCanGo = MainLogic.gameMap.canNotGo(this.iPlayerX + iStepx, this.iPlayerY + iStepy, this.byPlayerDirection);
            if (bCanGo == 0 || bCanGo == 2) {
                return true;
            }
        }
        switch (this.byPlayerUpdateDirection) {
            case Constant.PLAYER_DIRECTION_DOWN:
                if (MainLogic.gameMap.canNotGo(this.iPlayerX + getPlayerXYStep(Constant.PLAYER_DIRECTION_LEFT, (byte) 1), this.iPlayerY + getPlayerXYStep(Constant.PLAYER_DIRECTION_LEFT, (byte) 2), this.byPlayerDirection) != 1) {
                    this.changeAction(Constant.PLAYER_STATE_RUN, Constant.PLAYER_DIRECTION_LEFT, true, false);
                    return true;
                } else if (MainLogic.gameMap.canNotGo(this.iPlayerX + getPlayerXYStep(Constant.PLAYER_DIRECTION_RIGHT, (byte) 1), this.iPlayerY + getPlayerXYStep(Constant.PLAYER_DIRECTION_RIGHT, (byte) 2), this.byPlayerDirection) != 1) {
                    this.changeAction(Constant.PLAYER_STATE_RUN, Constant.PLAYER_DIRECTION_RIGHT, true, false);
                    return true;
                }
                break;
            case Constant.PLAYER_DIRECTION_UP:
                if (MainLogic.gameMap.canNotGo(this.iPlayerX + getPlayerXYStep(Constant.PLAYER_DIRECTION_RIGHT, (byte) 1), this.iPlayerY + getPlayerXYStep(Constant.PLAYER_DIRECTION_RIGHT, (byte) 2), this.byPlayerDirection) != 1) {
                    this.changeAction(Constant.PLAYER_STATE_RUN, Constant.PLAYER_DIRECTION_RIGHT, true, false);
                    return true;
                } else if (MainLogic.gameMap.canNotGo(this.iPlayerX + getPlayerXYStep(Constant.PLAYER_DIRECTION_LEFT, (byte) 1), this.iPlayerY + getPlayerXYStep(Constant.PLAYER_DIRECTION_LEFT, (byte) 2), this.byPlayerDirection) != 1) {
                    this.changeAction(Constant.PLAYER_STATE_RUN, Constant.PLAYER_DIRECTION_LEFT, true, false);
                    return true;
                }
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                if (MainLogic.gameMap.canNotGo(this.iPlayerX + getPlayerXYStep(Constant.PLAYER_DIRECTION_DOWN, (byte) 1), this.iPlayerY + getPlayerXYStep(Constant.PLAYER_DIRECTION_DOWN, (byte) 2), this.byPlayerDirection) != 1) {
                    this.changeAction(Constant.PLAYER_STATE_RUN, Constant.PLAYER_DIRECTION_DOWN, true, false);
                    return true;
                } else if (MainLogic.gameMap.canNotGo(this.iPlayerX + getPlayerXYStep(Constant.PLAYER_DIRECTION_UP, (byte) 1), this.iPlayerY + getPlayerXYStep(Constant.PLAYER_DIRECTION_UP, (byte) 2), this.byPlayerDirection) != 1) {
                    this.changeAction(Constant.PLAYER_STATE_RUN, Constant.PLAYER_DIRECTION_UP, true, false);
                    return true;
                }
                break;
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (MainLogic.gameMap.canNotGo(this.iPlayerX + getPlayerXYStep(Constant.PLAYER_DIRECTION_UP, (byte) 1), this.iPlayerY + getPlayerXYStep(Constant.PLAYER_DIRECTION_UP, (byte) 2), this.byPlayerDirection) != 1) {
                    this.changeAction(Constant.PLAYER_STATE_RUN, Constant.PLAYER_DIRECTION_UP, true, false);
                    return true;
                } else if (MainLogic.gameMap.canNotGo(this.iPlayerX + getPlayerXYStep(Constant.PLAYER_DIRECTION_DOWN, (byte) 1), this.iPlayerY + getPlayerXYStep(Constant.PLAYER_DIRECTION_DOWN, (byte) 2), this.byPlayerDirection) != 1) {
                    this.changeAction(Constant.PLAYER_STATE_RUN, Constant.PLAYER_DIRECTION_DOWN, true, false);
                    return true;
                }
                break;
        }
        return false;
    }

    /**
     * 销毁静态变量
     */
    public static void clearStaticVariable() {
        //路径点存储路径
        verAutoRunPath = null;
        //存储tag目标点
        iArrayAutoRunTagPos = null;
        //玩家寻路路径点数组
        iAutoRunPoint = null;
        //测试用技能参照表
        strPlayerSkill = null;
        iPlayerSkillId = null;
        shPlayerSkillActId = null;
        iPlayerSkillDistance = null;
        iPlayerSkillUseMp = null;
        //2 --- 自身
        byPlayerSkillType = null;
        //敌对释放  队友释放
        bySkillType = null;
        iPlayerSkillCoolTime = null;
        iPlayerSkillStartTime = null;//= new long[Constant.QUICKSET_NUMS]
        iPlayerSkillCoolSpaceTime = null;//= new long[Constant.QUICKSET_NUMS]

    }
    //万家挂机
    private int iHangUpIndex = 0;

    public void playerHangUpLogic() {
        iHangUpIndex++;
        if (iHangUpIndex > 2000) {
            iHangUpIndex = 0;
        }
        //执行需求判断
        this.playerHangup();
        if (this.byPlayerState == Constant.PLAYER_STATE_STAND && this.byPlayerState != Constant.PLAYER_STATE_DIE) {
            //1 战斗
            MainLogic.getInstance().playerFightLogic((byte) 0, true);//
        }
    }

    public void playerHangup() {
        //如果设置了挂机使用补血蓝药品挂机时血量低于自身血量的30% 并且物品非冷却中
        if (iHangUpIndex % 3 == 0) {
            if (this.iPlayerHP == 0 || (this.iPlayerMaxHP / this.iPlayerHP >= 3)) {
                hangUpUseGood((byte) 0);//使用物品
            } else if (this.iPlayerMP == 0 || (this.iPlayerMaxMP / this.iPlayerMP >= 3)) {
                hangUpUseGood((byte) 1);//使用物品
            }
        }
        if (Property.hangUpSet[6] == true && !GameBean.BL_PLAYER_HANGUP_DOUBLEEXP)//如果设置了使用双倍经验并且非双倍经验状态
        {
            //如果
            hangUpUseGood((byte) 2);//使用经验卡
        }
    }
    private int iuseHPGoodIndex = 0;
    private int iuseMPGoodIndex = 0;
    public static int iuseSkillIndex = 0;
    public static boolean iHangUpUseGoodsLock = false;

    public void hangUpUseGood(byte type) {
        if (iHangUpUseGoodsLock) {
            return;
        }
        switch (type) {
            case 0://如果补HP物品
//                      if()//如果设置了补血物品并且物品存在(数量大于0) 否则返回
                iuseHPGoodIndex = Property.getGoodsIndex(0);
                if (iuseHPGoodIndex != -1) {
                    if (Property.lHangupCoolTIme[iuseHPGoodIndex][0] == 0) {//存在物品并且物品非冷却中
                        GameBean.L_CMD_GOODS_SLOTKEY = Property.getGoodsKey(iuseHPGoodIndex);// 
                        GameBean.BY_CMD_COLUMN_TYPE = Constant.ITEM_COLUMN_TYPE_COMMON;
                        Constant.ITEM_OPERATION_TYPE_RECORD = Constant.ITEM_OPERATION_TYPE_GAMESET;
                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_USE_ITEM, Constant.SOCKET_MSG_TYPE_LOGIC);
                        iHangUpUseGoodsLock = true;
                    }
                } else {
                    Property.hangUpSet[4] = false;//关闭使用mp
                }
                break;
            case 1://补MP物品
                iuseMPGoodIndex = Property.getGoodsIndex(3);
                if (iuseMPGoodIndex != -1) {//存在物品并且物品非冷却中
                    if (Property.lHangupCoolTIme[iuseMPGoodIndex][0] == 0) {
                        GameBean.L_CMD_GOODS_SLOTKEY = Property.getGoodsKey(iuseMPGoodIndex);//
                        GameBean.BY_CMD_COLUMN_TYPE = Constant.ITEM_COLUMN_TYPE_COMMON;
                        Constant.ITEM_OPERATION_TYPE_RECORD = Constant.ITEM_OPERATION_TYPE_GAMESET;
                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_USE_ITEM, Constant.SOCKET_MSG_TYPE_LOGIC);
                        iHangUpUseGoodsLock = true;
                    }
                } else {
                    Property.hangUpSet[5] = false;//关闭使用mp
                }
                break;
            case 2://双倍经验卡
                //如果得到的双倍经验卡非空则使用
                long goodskey = Property.getGoodsKey(6);
                if (goodskey != 0) {
                    GameBean.L_CMD_GOODS_SLOTKEY = goodskey;// 测试用
                    GameBean.BY_CMD_COLUMN_TYPE = Constant.ITEM_COLUMN_TYPE_COMMON;
                    Constant.ITEM_OPERATION_TYPE_RECORD = Constant.ITEM_OPERATION_TYPE_GAMESET;
                    MainLogic.getInstance().send(Constant.MSG_NET_CMD_USE_ITEM, Constant.SOCKET_MSG_TYPE_LOGIC);
                    iHangUpUseGoodsLock = true;
                } else {
                    Property.hangUpSet[6] = false;//关闭使用挂机卡
                }
                break;
        }
    }
}
